我们可以使用sql server 2008创建序列吗? [英] can we create sequences using sql server 2008?
本文介绍了我们可以使用sql server 2008创建序列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以使用sql server 2008创建序列吗?
推荐答案
嗨..
这是按顺序返回Dates的Sql语句块....
Hi..
Here is the block of Sql statements which returns Dates in sequence....
--Variable declaration
declare @FromDate DATE = '2012-12-01';
declare @ToDate DATE = GETDATE();
--RECURSIVE CTE(Common Table Expression)
with mycte as (
select cast(@FromDate as datetime) DateValue
union all
select DateValue + 1
from mycte
where DateValue + 1 < @ToDate
)
select DateValue
from mycte
OPTION (MAXRECURSION 0)
谢谢。
Thank you.
SQL Server 2008还不知道序列。
对于几乎相同的结果,请使用INT IDENTITY列:
SQL Server 2008 doesn''t know sequences yet.
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,
....
)
当您在新行中插入新行时,SQL Server会自动填充IDENTITY列。表。
基本上,在向这样的表中插入行时,不能在列表中指定IDENTITY列以插入值 - SQL Server将为此执行此操作你自动。
The IDENTITY column is automatically filled by SQL Server at the time you insert a new row into the table.
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创建序列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文