What are the magic tables available in SQL Server 2000?
Sql server creates two temprory tables(Inserted and Deleted) when the INSERT, UPDATE, DELETE operation performed.These tables are called Magic tables.When Insert Operation performed, Inserted table also contain theses values.When Update Operation performed,the old values inserted in Deleted table and new values inserted in Inserted table.When Delete Operation performed, Deleted table contain these values.Magic table is used for Trigger handling.
in a simple words magic table are Inserted tables and deleted tables.Which is used in trigger handling.e.g if we've set a trigger on a table and when any of these actions(inserted,deleted,Updated) fire on any table @ moment trigger fires and gets the last updated value of triggered table modified by DML statements.NOTE;Inserted and Deleted has been introduced as keywords in SQLServer 2008
Magic table is automatic generated table in mssql server . it is use in Trigger Handling
Sql Server automatically creates and manages two temporary, memory-resident tables (deleted and inserted tables) which are popularly known as magic tables.
Magic tables are used to put all the deleted and updated rows. We can retrieve thecolumn values from the deleted rows using the keyword "deleted"To project the deleted data into the deleted table we will use "output" clauseBelow is the sample code to retrieve the deleted data.
DECLARE @DeletedTable TABLE(DeletedTableID INT, DeletedData VARCHAR(20))
Code Snippet:
DELETE VENKATOutputOUTPUT Deleted.KeyID, Deleted.Name INTO @DeletedTable WHERE KeyID > 3SELECT * FROM @DeletedTable
Similarly, we can retrieve the updated data and old data too using the keyword "Inserted"
Yes, this is the exact answer what has been given by Praveen.Thanks PraveenManoj(InfoAxon Technologies Limited)
The INSERTED and DELETED tables, popularly known as MAGIC TABLES, and update () and columns_updated() functions can be used to determine the changes being caused by the DML statements.Note that the Magic Table does not contain the information about the columns of the data-type text, ntext, or image. Attempting to access these columns will cause an error.
This answer was posted at dotnetspider
Reference URL:
http://www.dotnetspider.com/kb/Article1733.aspx