Share via


SQL Server 2012 T-SQL - Working with Sequence

One of the T-SQL enhancemtns in SQL Server 2012 addition of Sequence.  You can use sequence to generate a sequential number that can use utilized for various purpose. Here is simple example of using Sequence to populate sequential number to a table.

  

 Create Table dbo.Employee
 (
 EmployeeID Int, 
 FirstName Varchar(30) 
 );
 
 Create Sequence dbo.EmpIDSeq
 As Int Start with 1 increment by 1;
 
 Insert Into Employee(EmployeeID,FirstName)
 values
 (next value for dbo.EmpIDSeq,'John'),
 (next value for dbo.EmpIDSeq,'Mike');
 
 Select * from Employee;
 You can create the same using Managemet Studio UI - Database/Programmability/Sequences.