2

How can we create sequence in SQL Server? I am creating like this

CREATE SEQUENCE counter
AS INT
MINVALUE 1
NO MAXVALUE
START WITH 1;

but getting below error

Msg 343, Level 15, State 1, Line 1
Unknown object type 'SEQUENCE' used in a CREATE, DROP, or ALTER statement.

Thanks in advance

1
  • Which version MS SQL Server do you use ? As I know SEQUNCE's have been added only in 2012 version. Commented Feb 27, 2014 at 10:56

1 Answer 1

6
CREATE SEQUENCE CountBy1
    START WITH 1
    INCREMENT BY 1 ;

    SELECT next value for CountBy1

In SQL Server 2012 above is the syntax to create and consume created sequence.

Sign up to request clarification or add additional context in comments.

2 Comments

Sequences have been added only in 2012 version
By mistake i wrote 2008 version. i have updated the given answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.