Reputation:
Please explain what the following statements mean. It's an assignment of local variables but I do not understand what inserted
or deleted
means?
select @ID = ID from inserted
select @co_ID = co_ID from deleted
Thank you
Upvotes: 0
Views: 91
Reputation: 191
INSERTED and DELETED are temporary, memory resident tables created by SQL Server for use (or misuse) within a DML trigger.
Inserts and updates copy new rows into INSERTED, Deletes and updates copy old rows into DELETED.
It looks like this code is attempting to audit a change to a row of data - but will fail unless there is something else in the code path guaranteeing that only a single row will be updated.
Upvotes: 2
Reputation: 1269603
These statements mean that you have written a trigger in SQL Server that is not safe. The trigger assumes that only one row has been updated. This is not safe because SQL Server calls triggers based on groups of rows.
If there is one row, then the parameters @ID
and @co_ID
are assigned values from that row. If there are multiple rows being updated, then values from arbitrary -- and perhaps different -- rows are assigned to the parameters.
Upvotes: 0