Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 how many times could you use SCOPE_IDENTITY()

Author  Topic 

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2004-12-10 : 14:58:19
hi,
how many times could you use SCOPE_IDENTITY() in a trigger or in a SP ?

RGDS

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-12-10 : 15:23:05
BOL says:

Returns the last IDENTITY value inserted into an IDENTITY column in the same scope. A scope is a module -- a stored procedure, trigger, function, or batch. Thus, two statements are in the same scope if they are in the same stored procedure, function, or batch.

so you do first identity insert and scope_identity will return you that one. you do the next insert and it will return you the next one... so basically as much as you want.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2004-12-10 : 16:07:19
Afrika,

Be aware that for multi-row inserts you cannot keep calling Scope_Identity to get each identity column value. The trigger executes AFTER the insert so you should be able to look into the inserted virtual table to get this information.

HTH

=================================================================

Happy Holidays!
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-12-10 : 20:58:07
>> how many times could you use SCOPE_IDENTITY() in a trigger or in a SP ?

As many times as you wish.
It may not return the value you require but it will always succeed.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -