SQL Server 2008 Express Edition - 如何创建序列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7999448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server 2008 Express Edition - how to create a sequence
提问by user437925
I'm using SQL Server 2008 Express Edition.
我正在使用 SQL Server 2008 速成版。
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!
此致!
回答by marc_s
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 (fka "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).
IDENTITY
在向表中插入新行时,SQL Server 会自动填充该列。SQL Server 确保它是单调递增的,从 1 开始,递增 1(如果需要,您可以将它们设置为不同的值)。
Basically, when inserting a row into such a table, you must notspecify the IDENTITY column in your list of columns to insert values into - SQL Server will do this for you automatically.
基本上,在向此类表中插入一行时,您不得在列列表中指定 IDENTITY 列以将值插入其中 - SQL Server 会自动为您执行此操作。
回答by Eralper
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.aspxfor 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