@@Identity and triggers
-
I've got an issue that I'd like to find a better solution to, I'm inserting a new row into a table, which fires of a trigger that does a set of inserts to replace something that used to be done manually. Previously I had been using @@Identity to retrieve the ID of the new row I inserted, however since I added the trigger I was getting the ID of the last item the trigger inserted. I've found SELECT IDENT_CURRENT('tbl'), which works, but leaves me concerned with potential concurrency issues. Any better methods out there or should I consider killing off the trigger to ensure the correct ID will always be returned?
-
I've got an issue that I'd like to find a better solution to, I'm inserting a new row into a table, which fires of a trigger that does a set of inserts to replace something that used to be done manually. Previously I had been using @@Identity to retrieve the ID of the new row I inserted, however since I added the trigger I was getting the ID of the last item the trigger inserted. I've found SELECT IDENT_CURRENT('tbl'), which works, but leaves me concerned with potential concurrency issues. Any better methods out there or should I consider killing off the trigger to ensure the correct ID will always be returned?
Read up on Scope_Identity() in BOL. This is a classic error when using triggers.
Never underestimate the power of human stupidity RAH