Open In App

SQL Query to Set First Day of the Week in a Database

Last Updated : 13 Apr, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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


Similar Reads

SQL Query to Get First and Last Day of a Week in a Database
An SQL query is a single line statement of a Program written in a particular language to perform a specific task. A query consists of some pre-defined functions in SQL like SELECT, CREATE, etc. So, in this article, we will learn about SQL query to get the first and last day of a week in a database. So let's create a database first to do our task, h
2 min read
SQL Query to get first and last day of a month in a Database
In this article, we will discuss the overview of SQL query to perform an operation on database and our main focus will be on how to get the First and Last Day of a Month in a Database in SQL. Let's discuss it one by one. Introduction :Queries in SQL help us to interact with the database to get done with the database creation, updating, retrieval, a
3 min read
Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
Structured Query Language (SQL): Structured Query Language (SQL) has a specific design motive for defining, accessing and changement of data. It is considered as non-procedural, In that case the important elements and its results are first specified without taking care of the how they are computed. It is implemented over the database which is drive
2 min read
SQL Query to Convert Date Range to Per Day Records
In this article, we are going to see how we can convert the date range to per day records, but before that, we need to have a clear idea of where it is going to be helpful for us. Suppose, We have a database where we want to store all the project details records of the students of a particular class. There we can see how long it took a student to c
5 min read
SQL Query to Add Email Validation Using Only One Query
In this article let us see how can we check for the validation of mails in the student database using MSSQL as the database server. For example, if the email is like abcdedfABCDEF...0123456@gmail.com this is the valid form of an email if it is other than this then that is said to Invalid. So, now we will discuss this concept in detail step-by-step:
2 min read
SQL Server Query to Find All Permissions/Access for All Users in a Database
There are multiple ways to list all the permissions for users present in a Database in Oracle SQL. Such ways are depicted in the below article. For this article, we will be using the Microsoft SQL Server as our database. Method 1: This method lists all the server level permissions granted to the user by the database. Here we are using the inbuilt f
2 min read
SQL Query to Add Ranking Positions of Rows in a Database With RANK()
In this article, we will discuss the overview of SQL function RANK and then our main focus will be on Add Ranking Positions of Rows in a Database With RANK() in SQL. Let's discuss it one by one. Overview :Generally, when max/min commands are executed, a single row is displayed as output. RANK() is an SQL function introduced in order to rank the row
2 min read
SQL Query to Add an Agent Parameter in a Database
In this article, we will learn how we add an extra or a new parameter after a table is created using ALTER command in Microsoft SQL Server in detail step-by-step: Step 1: Creating database sales by using the following SQL query: CREATE DATABASE sales; Step 2: Using the database sales by using the following SQL query: USE sales; Step 3: Creating a t
2 min read
SQL Query to Export Table from Database to CSV File
SQL Server is very popular in Relational Database, because of its versatility in exporting data in Excel/CSV/JSON formats. This feature helps with the portability of data across multiple databases. In this article, let us see how to import and export SQL Server Data to a CSV file. Azure data studio is a very useful tool for export options and the b
3 min read
SQL Query to Rename Database
To rename a database in SQL use the ALTER DATABASE Statement with MODIFY NAME clause. The ALTER command in SQL is used to make changes to a table or database. In this article, we will learn how to use the ALTER DATABASE statement with the MODIFY NAME clause to rename a database. How to Rename Database in SQL?To change the name of a database in SQL,
1 min read
Article Tags :