Triggers in Sql Server : Part - 2

In Previous article, we learnt about what is trigger.

In this article, 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 article, we will discuss the examples of different types of triggers and how to use these magic tables in triggers.
<< Prev Home Next >>
Triggers in Sql Server : Part - 2 Triggers in Sql Server : Part - 2 Reviewed by Sandeep Mittal on Tuesday, June 25, 2013 Rating: 5

No comments:

Powered by Blogger.