Hi,
Sequence can be created either
- Using TSQL statement or by
- Using SQL Server Management Studio (SSMS)
Note : Sequence is an object that has start value,
increment value and end value defined in them and this sequence can be
added to a column whenever required rather than defining an identity
column individually for tables.
Lets take a quick look,
How to create a SEQUENCE using TSQL Statements
- Sequence can be created using a Create SEQUENCE Syntax
------ Create a SEQUENCE object on schema "dbo" by the name of TEST_Sequence
CREATE SEQUENCE TEST_Sequence
AS INT
START WITH 1
INCREMENT BY 1
MINVALUE 0
NO MAXVALUE
Lets take a quick look, How to use to SEQUENCE in populating values in table
--- Creating a Table Named Customer
CREATE TABLE Customer
(
Id INT NOT NULL,
Name VARCHAR(100) NOT NULL
)
go
----Populating Customer table, using TEST_Sequence to generate the Id column:
INSERT Customer (Id, Name)
VALUES
(NEXT VALUE FOR TEST_Sequence, 'Ram'),
(NEXT VALUE FOR TEST_Sequence, 'Rita'),
(NEXT VALUE FOR TEST_Sequence, 'Ron')
Lets’ Look at results, which we inserted using SEQUENCE
---Selecting Records form Customer Table
SELECT * FROM Customer
http://sqlserver-training.com/wp-content/uploads/image47.png
Hope it helps,,,,