Set a new, specific value for SQL sequence

30 Views Asked by At

I have created a sequence to my database as follows:

DECLARE @max int;
SELECT @max = MAX(customernumber)+1
FROM organisation

exec('CREATE SEQUENCE organisation_customernumber_sequence
    START WITH ' + @max +
'   INCREMENT BY 1;')

It works and can be used in the application as intended. However, now there's a requirement to have it start from the number 40000.

Somehow I've managed to not find a way to do this. What is the simplest way to set my organisation_customernumber_sequence to 40000 with a single query?

1

There are 1 best solutions below

0
Steve Waters On

ALTER SEQUENCE organisation_customernumber_sequence RESTART WITH 40000;

GO