What is Row_Number() in SQL ?

Hello everyone, today I am going to discuss the Row_number feature in SQL server.

what is Row_Number()?

Row_Number is used to generate the number of each row dynamically in a sequential order based on some column orders.

Row_Number() must be used with order by clause, without order by we can not use the Row_Nuber function.

Row_Number() over(order by EmpName) as RowNumber

Example:

Generate unique Id for each row dynamically: – In case if the table does not have a primary key or any unique identification number. you can use Row_Number to provide the unique ID for a table.

select 
Row_Number() over(Order by EmailId) as Id,
EmailId,FirstName,LastName 
from 
Employee

Output from the above SQL Query
Row_Number_UniqueId

 

 

 

 

 

You can also watch video 

Catch us on social media

Author Profile

Deependra Kushwah
Deependra Kushwah
Deependra is a Senior Developer with Microsoft technologies, currently working with Opteamix India business private solution. In My Free time, I write blogs and make technical youtube videos. Having the good understanding of Service-oriented architect, Designing microservices using domain driven design.

Deependra Kushwah

Deependra is a Senior Developer with Microsoft technologies, currently working with Opteamix India business private solution. In My Free time, I write blogs and make technical youtube videos. Having the good understanding of Service-oriented architect, Designing microservices using domain driven design.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

RSS
Facebook
Google+
https://betechnical.blog/2017/10/31/what-is-row_number-in-sql">
Twitter
YouTube
Pinterest
Pinterest
LinkedIn
Instagram
%d bloggers like this: