Sunday, August 15, 2010

SQL SERVER – MAGIC Tables – INSERTED and DELETED

Two Special temporary tables will play a vital role while creating a trigger on a table. Those two tables are called MAGIC Tables. they are – INSERTED and  DELETED.

These two tables are used to test the effects of certain data modifications and to set the conditions for trigger actions. these two tables contains the same data structure as that of the original table on  which the trigger will be created.

While inserting a new record, a new row will be inserted in the INSERTED table.

While updating a record, the old details will placed in the DELETED table as a new record and the changes will be updated in the Original table. At the same time a new record will be placed in the INSERTED table.

While deleting a record from the original table, a new record will be placed in the DELETED table and the corresponding record will be deleted from the original trigger table.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.