PopSQL

How to Alter Sequence in SQL Server

Auto-incrementing columns in tables start at 1 by default, but sometimes you may want them to start at a different number and to have multiple increments. These numbers are known as “sequences”, and this is how to create them in SQL Server:

-- syntax
create sequence schema_name.sequence_name as data_type
start with value
increment by value;

Some examples:

create sequence dbo.even_numbers as bigint
start with 2
increment by 2
minvalue 2 -- setting the minimum sequence value
maxvalue 10000; -- setting the maximum sequence value

create sequence dbo.negative_numbers as bigint
start with 0
increment by -1; -- sequence that increments backward

To alter the sequence so that IDs start with a different number, you can't just do an UPDATE. You have to use the ALTER SEQUENCE command:

alter sequence dbo.even_numbers with 10;
database icon
SQL editing that just rocks
PopSQL and SQL Server, better together