i need example of SQL Server Update Trigger, Get fields before and after updated to execute sql statments in another table
A:
you'll want the special trigger deleted and inserted tables. check it out here
nathan gonzalez
2010-06-06 06:32:47
+5
A:
SQL Server triggers have access to 2 "magic" tables that contain a row for each row that was inserted, updated, or deleted in the statement that caused the trigger to execute.
To find all of the inserted rows on a INSERT statement:
select * from inserted
For all of the deleted rows on a DELETE statement:
select * from deleted
For UPDATE statements, each row updated will be present in both the inserted and deleted tables. The inserted table will hold the new value of the row after the update statement, and the deleted table will hold the old value of the row just before the update statement. Join between the two tables to get what you need:
select i.*, d.*
from inserted i
join deleted d on (i.id = d.id)
Sean Reilly
2010-06-06 06:34:40
+1 thanks for the point about update rows being present in both deleted and inserted tables.
mdma
2010-06-08 11:46:49