
need ID from newly inserted record (altered by insert trigger on SQL server)
I'm using an insert trigger (SQL Server) to reproduce the counter
functionality in Access. When a new record is inserted without an ID (ID =
Null or 0), then it is assigned an ID (by the trigger) that is equal to the
highest ID in the table so far plus one. So far so good.
Well, how do I find out what that ID is? In a multiuser environment, it is
not possible to simply select the highest ID, because when two users who
insert a new record at the same time, it is impossible to distinguish the two
newly inserted records. Both users will believe that the highest record is
theirs, when in fact only one user actually owns the last record, and the
other users owns the next-to-last record.
It seems like I need something like a cursor, but I'm not sure how to
implement such a thing. Keep in mind that this is a problem in almost ALL of
my talbes, since most use a trigger of this sort, so I need a generic
solution, not a one-time fix for just this table.
Thanks in advance...
Joel