Click here to Skip to main content
15,883,772 members
Please Sign up or sign in to vote.
1.80/5 (3 votes)
what is magic table.different types of magic table
Posted
Updated 19-Dec-16 2:08am

The tables "INSERTED" and "DELETED" are called magic tables of the
SQL Server. We can not see these tables in the data base. But we can access these
tables from the "TRIGGER"

When we insert the record into the table, the magic table "INSERTED" will be created
In that table the current inserted row will be available. We can access this
record in the "TRIGGER".

When we update a record on the table where trigger is created, the magic tables "INSERTED" and "DELETED" both will be created, the Old data of the updating record will be available in "DELETED" table and, the new data will be availalble in "INSERTED" table, while accessing them inside the trigger.

When we delete the record from the table, the magic table "DELETED" will be created
In that table the current deleted row will be available. We can access this
record in the "TRIGGER".


Extracted from here :
http://www.dotnetspider.com/resources/29332-Magic-tables-SQL-Server.aspx[^]

Hope It Helps
 
Share this answer
 
v3
Comments
[no name] 10-May-14 8:22am    
*lol* "everybody" is speaking/writing about general/independed solutions...things like 3tear etc...now the magic tables should be used???
Usually Inserted and Deleted Tables are called Magic Tables.Magic Tables does not contain the information about

the Columns of the DataType text,ntext or image.These are maintained by SQL Server for internal processing whenver an update,insert,Delete occur on table.However we can refer these tables in Triggers.

Whenever an updated table statement is fired SQL Server Maintains the original row before updation in a deleted table and New(Updated) row in inserted table.
 
Share this answer
 
Have a look at this Magic Table in SQL Server[^].

For more results see this Google search[^].
 
Share this answer
 
create trigger c1_InsteadOfInsert on customer1 instead of Insert
as
begin
insert into customer1 select name,city,Country from inserted
end;

insert into customer1(Name,city,Country) values('sohan','Kushinagar','INDIA')

--it will display the inserted records instead of displaying 1 row affected
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900