Variables
258
When an insert causes referential integrity actions or fires a trigger,
@@identity
behaves like a stack. For example, if an insert into a table
T1
(with an identity or autoincrement column) fires a trigger that inserts a row
into table
T2
(also with an identity or autoincrement column), then the value
returned to the application or procedure which carried out the insert is the
value inserted into
T1
. Within the trigger,
@@identity
has the
T1
value
before the insert into
T2
and the
T2
value after. The trigger can copy the
values to local variables if it needs to access both.
@@identity and
triggers