Skip to content
Related Articles

Related Articles

SQL Query to Set First Day of the Week in a Database
  • Difficulty Level : Expert
  • Last Updated : 13 Apr, 2021

In this article, we are going to write a SQL script to Set the first day of the week in a Database. Below is the implementation for the same. You should have MSSQL in your server.

Query in SQL – 

A query is a request for data or information from a database table or combination of tables. This data can be used for various purposes like Training a model, finding the patterns in the data, etc.

Let’s start by creating a DataBase first –

Step 1:



CREATE DATABASE GFG

Step 2: Use this database –

USE GFG

Step 3: Create a table as the days

CREATE TABLE geeksforgeeks 
                  (VALUE integer,
                  FirstDay varchar(20))

Describe this table – 

sp_help 'dbo.daysData'

Schema of table

Step 4: Insert values in the table –

USE [GFG]
GO

INSERT INTO [dbo].[geeksforgeeks]
           ([VALUE]
           ,[FirstDay])
     VALUES
           (1, 'Monday')
GO

INSERT INTO [dbo].[geeksforgeeks]
           ([VALUE]
           ,[FirstDay])
     VALUES
           (2, 'Tuesday')
GO

INSERT INTO [dbo].[geeksforgeeks]
           ([VALUE]
           ,[FirstDay])
     VALUES
           (3, 'Wednesday')
GO

INSERT INTO [dbo].[geeksforgeeks]
           ([VALUE]
           ,[FirstDay])
     VALUES
           (4, 'Thursday')
GO

INSERT INTO [dbo].[geeksforgeeks]
           ([VALUE]
           ,[FirstDay])
     VALUES
           (5, 'Friday')
GO

INSERT INTO [dbo].[geeksforgeeks]
           ([VALUE]
           ,[FirstDay])
     VALUES
           (6, 'Saturday')
GO

INSERT INTO [dbo].[geeksforgeeks]
           ([VALUE]
           ,[FirstDay])
     VALUES
           (7, 'Sunday')
GO

Select all the values

Step 5: Check the existing First day of the week – 

SELECT @@DATEFIRST

Pre defined datefirst

Step 6: Now set the First Day of the week using DATEFIRST –

SET DATEFIRST 1

Step 7: Check the DATEFIRST value – 

Date first has been changed

As we can see we have successfully set our date first as 1 i.e, monday

My Personal Notes arrow_drop_up
Recommended Articles
Page :