Sequence is an user defined object that generates a sequence of a number.
/****** Create new Sequence Object ******/
CREATE SEQUENCE FirstSequence
START WITH 1
INCREMENT BY 1;
/****** Create Temp Table ******/
DECLARE @Employee TABLE
(
ID int NOT NULL PRIMARY KEY,
Employee nvarchar(100) NOT NULL
);
/****** Insert Some Data ******/
INSERT @Employee (ID, Employee)
VALUES (NEXT VALUE FOR MySequence, 'Maha'),
(NEXT VALUE FOR MySequence, 'Sam'),
(NEXT VALUE FOR MySequence, 'Ram');
/****** List the Data ******/
SELECT * FROM @Employee;
The output will be as follows:-------------
ID Employee
-------------
1 Maha
2 Sam
3 Ram
-------------
/****** Create new Sequence Object ******/
CREATE SEQUENCE FirstSequence
START WITH 1
INCREMENT BY 1;
/****** Create Temp Table ******/
DECLARE @Employee TABLE
(
ID int NOT NULL PRIMARY KEY,
Employee nvarchar(100) NOT NULL
);
/****** Insert Some Data ******/
INSERT @Employee (ID, Employee)
VALUES (NEXT VALUE FOR MySequence, 'Maha'),
(NEXT VALUE FOR MySequence, 'Sam'),
(NEXT VALUE FOR MySequence, 'Ram');
/****** List the Data ******/
SELECT * FROM @Employee;
The output will be as follows:-------------
ID Employee
-------------
1 Maha
2 Sam
3 Ram
-------------
No comments:
Post a Comment