SQL Server 2008 Express Edition - 如何创建序列

时间:2021-07-01 15:53:22

I'm using SQL Server 2008 Express Edition.

我正在使用SQL Server 2008 Express Edition。

I wanna create a sequence with this code:

我想用这段代码创建一个序列:

CREATE SEQUENCE Postoffice_seq
    AS bigint
    START WITH 1
    INCREMENT BY 1
    MINVALUE 0
    NO MAXVALUE;

and the error is

而错误是

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

消息343,级别15,状态1,行1在CREATE,DROP或ALTER语句中使用的未知对象类型“SEQUENCE”。

Can anyone help me?

谁能帮我?

Best Regards!

2 个解决方案

#1


10  

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

SQL Server 2008还不知道序列 - 这将在SQL Server 2012中引入(f.k.a。“Denali”)。

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

对于几乎相同的结果,请使用INT IDENTITY列:

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).

在您向表中插入新行时,SQL Server会自动填充IDENTITY列。 SQL Server确保它单调递增,从1开始增加1(如果需要,可以将它们设置为不同的值)。

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.

基本上,在将行插入此类表时,您不能在列列表中指定IDENTITY列以插入值 - SQL Server将自动为您执行此操作。

#2


0  

Sequence objects are new with SQL Denali, SQL Server 2012 Here is some sample codes http://www.kodyaz.com/sql-server-2012/number-of-sequences-in-sql-server-2012-using-sequence-objects.aspx for sequence objects in SQL 2012

SQL Denali,SQL Server 2012中的序列对象是新的。以下是一些示例代码http://www.kodyaz.com/sql-server-2012/number-of-sequences-in-sql-server-2012-using-sequence- SQL 2012中的序列对象的objects.aspx

You can find a sequence table implemantation for SQL Server 2008 here : http://www.kodyaz.com/t-sql/sql-server-instead-of-trigger-with-sequence-table.aspx

您可以在此处找到SQL Server 2008的序列表实现:http://www.kodyaz.com/t-sql/sql-server-instead-of-trigger-with-sequence-table.aspx

#1


10  

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

SQL Server 2008还不知道序列 - 这将在SQL Server 2012中引入(f.k.a。“Denali”)。

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

对于几乎相同的结果,请使用INT IDENTITY列:

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).

在您向表中插入新行时,SQL Server会自动填充IDENTITY列。 SQL Server确保它单调递增,从1开始增加1(如果需要,可以将它们设置为不同的值)。

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.

基本上,在将行插入此类表时,您不能在列列表中指定IDENTITY列以插入值 - SQL Server将自动为您执行此操作。

#2


0  

Sequence objects are new with SQL Denali, SQL Server 2012 Here is some sample codes http://www.kodyaz.com/sql-server-2012/number-of-sequences-in-sql-server-2012-using-sequence-objects.aspx for sequence objects in SQL 2012

SQL Denali,SQL Server 2012中的序列对象是新的。以下是一些示例代码http://www.kodyaz.com/sql-server-2012/number-of-sequences-in-sql-server-2012-using-sequence- SQL 2012中的序列对象的objects.aspx

You can find a sequence table implemantation for SQL Server 2008 here : http://www.kodyaz.com/t-sql/sql-server-instead-of-trigger-with-sequence-table.aspx

您可以在此处找到SQL Server 2008的序列表实现:http://www.kodyaz.com/t-sql/sql-server-instead-of-trigger-with-sequence-table.aspx