Okay. Now let's practice using sequence. Let's say we've created a database sequence called
IdSeq. We can use it to insert data into the
Post table, like this:
INSERT INTO Post (Id, AuthorId, Title, Text, ModifiedDateTime)
VALUES (NEXT VALUE FOR IdSeq, 4, N'A celebrity''s holiday',
N'Lucy, a celebrity, is going to spend lots of time on holiday in Japan.', DEFAULT);
In this query, we use
NEXT VALUE FOR to get the next value generated by our sequence. We put that value in the
Id column. The start value has been set to 16, and the increment value has been set to 1.
It's your decision when and where to use sequences. Just remember that it's an available option when you need to have unique identifiers for columns.