Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Triggers, On Insert

Status
Not open for further replies.

qsac

Programmer
Jan 22, 2002
242
0
0
US
I creted a Trigger to do certain things On Insert.

Is there a way I can get the Value of the Identity of the record I just inserted?

Thanks,
Q
 
i beleive that @@IDENTITY contains tht last identy inserted

so
Code:
select @@IDENTITY
 
Works like a charm.

Can i push my luck and ask how I would get the Identity of the Field updated, if i made an On Update trigger?

Thanks,
Q
 
Look in the Sql Server BOL for the 'Deleted' and 'Inserted' tables to find out more about handling the processed records in triggers.

Rhys

""Vampireware /n/, a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

I see dead pixels!
 
Hi,

Use Inserted or Deleted as described above if you want the ID for the row you have updated.
If you want to know what field you updated use ColumnsUpdated().

regards
/Mattias
 
IMHO COLUMNS_UPDATED() is hidden trouble maker - it relies on ordinal position of column(s) within a table. Theoretically this is bad thing - whether column 'foo' is 1st, 3rd or 99th shouldn't matter. Practically - trigger might check wrong columns if you don't declare them in exactly the same order. Such logical errors are hard to trace. And if column position is greater than 8, expressions get ugly (bitmask manipulations).

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top