Discussion Locked

Reference data in a SQL Server trigger

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How can I refer to the data in a field that kicks of a trigger within the trigger procedure itself? An update to field(A) kicks off trigger(T), but the procedure in trigger(T) needs the value stored in field(A)for comparison purposes. How can I refer to it? Where is it stored? System table?

5 replies

by roc180

Use the system table Inserted.

SELECT FieldA FROM Inserted

If you need to compare the old value to the new check the system table Deleted.

Good Luck

Neal Martinelli

by glen_mcleod

When a trigger is fired, 2 virtual table become available called 'inserted' and 'deleted'. On a delete, the 'inserted' table will be empty but the 'deleted' table will have data, and the opposite for an insert.

On an update, the old data will be in 'deleted', and the new data will be in 'inserted', so just reference these tables as you need.

There're *only* available to triggers.

Glen

This discussion is closed to new replies.