替代 SQL Server 中 Oracle 的 select.nextval?
有没有办法在 SQL Server 中创建唯一的序列号
select <sequence>.nextval from dual
我们有上面的 Oracle 代码,它将创建一个唯一的编号,并且该编号不能被任何其他人使用。
以同样的方式,我如何在 SQL Server 中创建唯一的序列号???
有人在这方面帮助我
Is there any way to create a unique sequence no in SQL Server
select <sequence>.nextval from dual
We have the above code for Oracle which will create a unique number and the number cannot be used by any other.
In the same way how can I create a unique sequence number in SQL Server????
Some one help me in this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SQL Server 2012 中正在添加序列 - 但尚未完全发布。如果您想提前试用,该产品的候选版本已经包含在内。
如果序列仅由单个表使用,则可以使用标识列功能,该功能允许您指定起始编号和每条记录添加的值。
如果您正在寻找可在多个表中使用的序列,则需要在 SQL Server 中创建一个专用表,该表具有单列标识字段 - 每当您需要 .nextval 时,您都可以插入在表中一行以获取新数字。该表的作用就像一个序列。该表将随着时间的推移而填满,不需要在表中保留记录,标识存储其当前值和增量以获取系统表上的下一个值。
Sequences are being added in SQL Server 2012 - but this is not quite released as yet. The release candidates for the product has them in if you want to try them out in advance.
If the sequence is to just be used by a single table, then you can use the identity column feature, which allows you to specify a starting number and the value added per record.
If you are looking for a sequence that can be used across a number of tables, you would need to create a dedicated table within SQL server, that has a single column of an identity field - and whenever you wanted a .nextval, you would insert a row into the table to get a new number. The table than acts like a sequence. The table will fill up over time, there is no requirement to keep records within the table, the identity stores it's current value and increment to obtain the next value on a system table.
只有即将推出的 SQL Server 2012 支持符合 SQL 标准的序列对象。 :-( 在 SQL Server 的任何当前版本(2008 R2 及更低版本)中,您必须使用具有身份约束的列,如下所示:
这将在 id 列中生成从 1 开始的值,并以 1 为步长递增。
Only the upcoming SQL Server 2012 supports a sql standard conform sequence object. :-( In any current version of SQL Server (2008 R2 and below) you must use a column with the identity contstraint as in:
This will generate values in the id column starting with 1 and incrementing them in steps of 1.