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.
| Author |
Topic |
|
matkwan
Starting Member
36 Posts |
Posted - 2003-10-10 : 09:33:02
|
| Hi,I would like to have a trigger to find out the Rec ID (identity) of an inserted and updated record to the table, is it possible ? * I think I can use this "SELECT IDENT_CURRENT('tablename')" to find out the inserted Rec ID.* But don't know how to find out the updated Record ID.Please Help,Thanks in advanceMatthew |
|
|
OMB
Yak Posting Veteran
88 Posts |
Posted - 2003-10-10 : 10:29:51
|
| matthewtry this CREATE TRIGGER trecID on tablenamefor insertdeclare @recID numeric(18,0)select @recid = i.recID from inserted iprint @recid OMB |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2003-10-10 : 11:03:16
|
People have a hard time wrapping their minds around triggers that fire as a result of multi-row DML. OMB, what would you trigger do if I ..inesrt tablename (recID)select 1 as recIDunion alllselect 2 as recid ... your trigger will only print 1 or 2, but not both.matkwan, you need to clarify your business rule. Do you want the greatest identity value, or all of the identities from the DML? If you just want the greatest, have a look at "@@identity" in Books Online.Jay White{0} |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-10-10 : 11:07:29
|
| This is "set based processing world"A trigger can fire for 1 to n records....Brett8-) |
 |
|
|
|
|
|