SQL Server - Working with sequences

The usage of sequences allows us to generate a new table row id that is unique across tables.

To create a new sequence use this syntax:

CREATE SEQUENE MySeq
START WITH 1
INCREMENT BY 1

Then when inserting a new row to a table, use this:

INSERT INTO MyTable(Id,Name)
VALUES (NEXT VALUE for MySeq, 'My Name')





Post a Comment

Previous Post Next Post