SQL Server 2008 Express Edition - how to create a sequence

后端 未结 2 621
孤城傲影
孤城傲影 2021-01-12 22:40

I\'m using SQL Server 2008 Express Edition.

I wanna create a sequence with this code:

CREATE SEQUENCE Postoffice_seq
    AS bigint
    START WITH 1
          


        
2条回答
  •  旧巷少年郎
    2021-01-12 23:34

    SQL Server 2008 doesn't know sequences yet - that'll be introduced in SQL Server 2012 (f.k.a. "Denali").

    For pretty much the same result, use an INT IDENTITY column instead:

    CREATE TABLE dbo.YourTable
      (YourID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
        ....
      )
    

    The IDENTITY column is automatically filled by SQL Server at the time you insert a new row into the table. SQL Server makes sure it's monotonically increasing, starting at 1, increasing by 1 (you can set these to different values, if needed).

    Basically, when inserting a row into such a table, you must not specify the IDENTITY column in your list of columns to insert values into - SQL Server will do this for you automatically.

提交回复
热议问题