问题描述
mssql中是否有与SQL Anywhere的GET_IDENTITY相同的
保留表的下一个autoinc值?是的我知道
@@ Identity和SCOPE_IDENTITY。我需要获得下一个autoinc值
_before_由于现有应用程序
的工作方式,我插入记录。
我看过DBCC CHECKIDENT,但这对我来说似乎很吵。
TIA,
Jim
Is there an equivalent in mssql to SQL Anywhere''s GET_IDENTITY which
reserves the next autoinc value for a table? Yes I know about
@@Identity and SCOPE_IDENTITY. I need to get the next autoinc value
_before_ I insert the record due to the way the existing application
works.
I''ve seen DBCC CHECKIDENT mentioned but that seems kludgy to me.
TIA,
Jim
推荐答案
您无法可靠地确定下一个IDENTITY值,除非在
a单用户系统中。不过还有其他方法:
-
David Portas,SQL Server MVP
只要有可能,请发布足够的代码来重现您的问题。
包含CREATE TABLE和INSERT语句通常会有所帮助。
State你正在使用什么版本的SQL Server并指定内容
的任何错误消息。
SQL Server联机丛书:
-
You cannot reliably determine the next IDENTITY value, except maybe in
a single user system. There are other ways however:
http://www.sqlmag.com/Article/Articl...ver_48165.html
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--
函数ident_current()是您要查找的函数,但它返回的值
对所有进程都是全局的,所以如果你调用ident_current(),
插入一行,然后看看scope_identity()你可能会看到一个不同的
值,如果另一个进程在同一时间。
-
Erland Sommarskog,SQL Server MVP,
SQL Server 2005联机丛书
用于SQL Server 2000的联机书籍
The function ident_current() is the one you are looking for, but the value
it returns is global to all processes, so if you call ident_current(),
insert a row and then look at scope_identity() you may see a different
value, if another process was at it at the same time.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
这篇关于相当于SQL Anywhere GET_IDENTITY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!