What is magic table in sql server and In which situation we use it ?
Magic Tables in SQL Server
Hi all,
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
V S N Raju KanumuriRank #8,839 · 215 reputationPosted Oct 18, 2012, 11:40 AM EDT
This Magic table are used In SQL Server 6.5, 7.0 & 2000 versions with Triggers only.
But, In SQL Server 2005, 2008 & 2008 R2 Versions can use these Magic tables with Triggers and Non-Triggers also.
Using with Triggers:
If you have implemented any trigger for any Tables then,
1.Whenever you Insert a record on that table, That record will be there on INSERTED Magic table.
2.Whenever you Update the record on that table, That existing record will be there on DELETED Magic table and modified New data with be there in INSERTED Magic table.
3.Whenever you Delete the record on that table, That record will be there on DELETED Magic table Only.
These magic table are used inside the Triggers for tracking the data transaction.
Using Non-Triggers:
You can also use the Magic tables with Non-Trigger activities using OUTPUT Clause in SQL Server 2005, 2008 & 2008 R2 versions.
Pradip PandeyRank #452 · 5.6K reputationPosted Oct 17, 2012, 3:17 AM EDT
When you create a trigger either for insert or delete, 2 tables are created by SQL server & they are inserted & deleted table. These tables are called Magic Table.
Hope it will help.
Satyapriya NayakRank #47 · 31.5K reputationPosted Oct 17, 2012, 3:23 AM EDT
Please refer the below links
http://vishalnayan.wordpress.com/2011/04/14/what-is-magic-table-in-sql-server/
http://www.dotnetspider.com/resources/29332-Magic-tables-SQL-Server.aspx
Thanks