Search This Blog

Friday, January 28, 2011

What are magic tables in SQL Server?

a. Whenever a trigger fires in response to the INSERT,DELETE,or UPDATE statement,two special tables are created.These are the insert and the delete tables.They are also referred to as the magic tables.These are the conceptual tables and are similar in structure to the table on which trigger is defined(the trigger table).
The inserted table contains a copy of all records that are inserted in the trigger table.
The deleted table contains all records that have been deleted from deleted from the trigger table.Whenever any updation takes place,the trigger uses both the inserted and deleted tables.

  
b. There are 2 Magic Tables in SQL server Inserted and Deleted.
These are mantained by SQL server for Internal processing whenever an update, insert of delete 
occur on a table. However, we can refere these tables in a Trigger.Whenever an update table 
statement is fired SQL server mantains the  original row before updation in a deleted table and 
New (updated )row in a Inserted Table. Same is the case when an insert is fired Only Inserted 
table is populated with inserted Row.and when Delete table statement is fired Deleted 
table is populated with the deleted row.

 

No comments:

Post a Comment