vba 我如何在 sql server 中使用 SELECT @@identity?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3526554/
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
HOW do i use SELECT @@identity in sql server?
提问by l--''''''---------''''''''''''
i am currently calling SELECT @@identity from VBA in mysql:
我目前正在 mysql 中从 VBA 调用 SELECT @@identity:
Set rs = cn.Execute("SELECT @@identity", , adCmdText)
but since i am going to be working with sql server db instead of mysql, i would like to know how to make this statement sql-server friendly
但由于我将使用 sql server db 而不是 mysql,我想知道如何使这个语句对 sql-server 友好
would it just be Set rs = cn.Execute("SCOPE_IDENTITY()", , adCmdText)
??
会是这样Set rs = cn.Execute("SCOPE_IDENTITY()", , adCmdText)
吗??
采纳答案by bobs
Both SQL statements are valid, with one exception. Change
两个 SQL 语句都是有效的,只有一个例外。改变
"SCOPE_IDENTITY()"
to
到
"SELECT SCOPE_IDENTITY()"
The difference between the two is that the @@identity
variable contains the most recent identity value on the SQL Server (global perspective). The SCOPE_IDENTITY()
function returns the most recent local identity.
两者之间的区别在于该@@identity
变量包含 SQL Server 上的最新标识值(全局角度)。该SCOPE_IDENTITY()
函数返回最近的本地身份。
You can find more on the SCOPE_IDENTITY
here.
回答by Geoff
If you're asking about the T-SQL side of it, then you should be able to just use the same statement (i.e. 'SELECT @@identity').
如果您询问它的 T-SQL 方面,那么您应该能够使用相同的语句(即“SELECT @@identity”)。