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
 General SQL Server Forums
 New to SQL Server Programming
 Im having an @@Identity crisis

Author  Topic 

Ishamael
Starting Member

14 Posts

Posted - 2006-09-27 : 01:57:07
End of the day so I wont be replying for a few hours.
And I know I should look through the forums, will do tomorrow if no one replys:P

You know how @@Identity gives you the row you just inserted.. is there a similar way to get the idenity of a row you just updated.. Its for a trigger.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-27 : 02:16:31
Use the inserted and/or deleted tables.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2006-09-27 : 02:23:22
You would use the INSERTED table. The INSERTED table (and the DELETED table) contain a copy of the rows prior to being modified. You can just select out the identity value from this special table during your update operation.

check BOL regarding triggers for more infomation.


EDIT:





-ec
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-09-27 : 13:18:35
"is there a similar way to get the idenity of a row you just updated [in a trigger]"

Note that the INSERTED and DELETED pseudo-tables can contain MULTIPLE records - so be careful to write your triggers to assume multiple rows, rather than just a single row!

Kristen
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-27 : 13:21:44
Yea,

SELECT IdentCol FROM table WHERE whatever you predicate was

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Ishamael
Starting Member

14 Posts

Posted - 2006-09-27 : 18:47:43
Thanks guys will look into it :)
Go to Top of Page
   

- Advertisement -