What are the magic tables in SQL Server 2000?

Answer Posted / deepak rawat

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 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".

Following code Explain the magic table "DELETED"

CREATE TRIGGER LogMessageON EMPFOR DELETEAS DECLARE
@EMPNAME varchar(50) SELECT @EMPNAME= (SELECT EMPNAME
FROM DELETED) INSERT INTO LOGTABLE(UserId,Message) values
(@EMPNAME,'Record Removed')GO


The magic tables "INSERTED" and "DELETED" are main concept
of the "TRIGGER".
By using these tables we can do lot of useful
functionalities. The above code is
used to update the "LOGTABLE"

Is This Answer Correct ?    12 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are “phantom rows”?

1248


How to apply filtering criteria at group level with the having clause in ms sql server?

560


What are triggers? How do you invoke a trigger on demand?

751


What do you mean by cardinality?

495


Why use update_statistics command in sql server?

558






Explain try...catch with sql server?

601


What are data resources?

506


What is a with(nolock)?

579


Explain about SQL server 2005?

563


What is change tracking in sql server?

550


What is the syntax to execute the sys.dm_db_missing_index_details? : sql server database administration

631


What is the purpose of a table?

524


What is the difference between clustered and non-clustered indexes in ms sql server?

493


How do you delete duplicate rows in sql server?

508


What is statement level trigger?

545