Unable to create sequence in SQL Server 2008

I tried to create a sequence in SQL Server 2008 using the following query:

CREATE SEQUENCE serial START 100

I got the following syntax error,

Msg 102, Level 15, State 1, Line 1
Invalid syntax next to "SEQUENCE".

How to create a sequence in SQL Server 2008?

+5
source share
3 answers

You just can't do it.

SQL Server 2008 has no idea SEQUENCE- this is a new feature in SQL Server 2012 (MSDN documentation here) .

, "auto-Increasing" - IDENTITY:

CREATE TABLE dbo.YourTable
( TableID INT IDENTITY,
 .....
+11

IDENTITY .

msdn:

+1

marc_s, SQL Server 2008 . . , . . .

:

create table IdSequence (id int identity(1,1))

script Id:

begin tran 
 insert into IdSequence output inserted.id default values 
rollback tran

:

    public Int32 GetNextId()
    {
        Int32 id = 0;
        using (var transaction = Session.BeginTransaction())
        {
            id = Session.CreateSQLQuery("insert IdSequence output inserted.id default values").UniqueResult<Int32>();
            transaction.Rollback();
        }

        return id;
    }
0
source

All Articles