问题描述
我使用的是 SQL Server 2008 Express Edition.
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
INCREMENT BY 1
MINVALUE 0
NO MAXVALUE;
错误是
消息 343,级别 15,状态 1,第 1 行
在 CREATE、DROP 或 ALTER 语句中使用了未知的对象类型SEQUENCE".
有人可以帮我吗?
最好的问候!
推荐答案
SQL Server 2008 尚不知道序列 - 这将在 SQL Server 2012(又名Denali")中引入.
SQL Server 2008 doesn't know sequences yet - that'll be introduced in SQL Server 2012 (f.k.a. "Denali").
要获得几乎相同的结果,请改用 INT IDENTITY
列:
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,
....
)
IDENTITY
列在您向表中插入新行时由 SQL Server 自动填充.SQL Server 确保它是单调递增的,从 1 开始,递增 1(如果需要,您可以将这些设置为不同的值).
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 会自动为您执行此操作.
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.
这篇关于SQL Server 2008 Express Edition - 如何创建序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!