@@ IDENTITY,SCOPE_IDENTITY()&上的差异IDENT_CURRENT [英] Difference on @@IDENTITY , SCOPE_IDENTITY() & IDENT_CURRENT

查看:87
本文介绍了@@ IDENTITY,SCOPE_IDENTITY()&上的差异IDENT_CURRENT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


上的差异 @@ IDENTITY vs SCOPE_IDENTITY()vs IDENT_CURRENT

感谢提前
〜JK

Need Differences on
@@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT

Thanx on advance
~JK

推荐答案

基本区别:
@@ IDENTITY:
返回在所有范围内为当前会话中的任何表生成的最后一个标识值.

SCOPE_IDENTITY
返回为当前会话和当前范围中的任何表生成的最后一个标识值.

IDENT_CURRENT:
返回在任何会话和任何作用域中为特定表生成的最后一个标识值.

有关此的更多信息,请尝试 google [ ^ ].


--Amit
The basic difference:
@@IDENTITY:
Returns the last identity value generated for any table in the current session, across all scopes.

SCOPE_IDENTITY
Returns the last identity value generated for any table in the current session and the current scope.

IDENT_CURRENT:
Returns the last identity value generated for a specific table in any session and any scope.

For more information about this, try google[^].


--Amit


看看以下博客
Have a look at the follow blog http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/[^]. You''ll find your answer there.




@@ IDENTITY将返回您最后插入的行值.
SCOPE_IDENTITY()将返回您当前表的插入值.

例如,
我有一个表"ABC",在其中添加了一条记录.它的主键值i将返回并假定为100.现在在插入表ABC的行中有一个触发器.使用该触发器,假设我要进入表"XYZ"中的插入记录.该行应该是200.

现在,如果您使用@@ IDENTITY,则它将返回200.最后插入的值.
如果您使用SCOPE_IDENTITY(),那么它将给您100.

我希望您能在此示例后获得灵感.

谢谢,
Viprat


@@IDENTITY will return you last inserted row value.
SCOPE_IDENTITY()will return your current table inserted value.

For Example,
I have one table ''ABC'' in which i add one record. Its primary key value i will return and suppose that is 100. Now there is one trigger in inserting row of table ABC. Using that trigger suppose i am going in insert record in Table ''XYZ''. That row is suppose 200.

Now if you user @@IDENTITY then it will return 200. Last inserted value.
if you user SCOPE_IDENTITY()then it will give you 100.

I hope you will get idea after this example.

Thanks,
Viprat


这篇关于@@ IDENTITY,SCOPE_IDENTITY()&上的差异IDENT_CURRENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆