What are Magic Tables in SQL Server?

Magic tables are the temporary logical tables that are created by the SQL server whenever there are insertion or deletion or update( D.M.L)  operations. The recently performed operation on the rows gets stored in magic tables automatically. These are not physical table but they are just temporary internal tables. These magic tables can’t be retrieved directly, we need to use triggers to access these magic tables to get the deleted and inserted rows. 

Types of magic tables

INSERTED – When any insert query executed, then the recently inserted row gets added to the INSERTED magic table.
 
DELETED – When any delete query executed, then the recently deleted row gets added to the DELETED magic table.

In update case, the updated row gets stored in INSERTED magic table and the old row or previous row gets stored in the DELETED magic table.

The use of magic tables are TRIGGERS.

 



Post a Comment

Previous Post Next Post