Tuesday, June 25, 2013

Triggers in Sql Server : Part - 2

In Part-1, we learnt about what is trigger.

In this part, we will learn about Magic tables in triggers.


Magic Tables are logical tables which are created automatically when DML operations (insert/update/delete") are performed. These tables temporarily holds the data depending upon the operation and are accessible in triggers.

There are two types of magic tables
  • Inserted
  • Deleted
Magic Tables "Inserted/Deleted" are created depending on the DML operation "insert/update/delete" performed
  • Insert : Inserted table is created when an insert operation is performed and holds recently inserted data in the table.
  • Update : Both Inserted and Deleted tables are created when an update operation is performed. Inserted table holds the updated rows (new data) while deleted table holds the old data of the rows which are updated as a result of update statement.
  • Delete : Deleted table is created when delete operation is performed and holds recently deleted data from the table.
In the next part, we will discuss the examples of different types of triggers and how to use these magic tables in triggers.

0 comments:

Post a Comment