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

How to trouble shoot if unable to connect SQL Server

1478


What do mean by xml datatype?

611


mention different types of relationships in the dbms?

503


what is the difference between them (ethernet networks and token ring networks)? : Sql server database administration

517


What is the difference between DataRow.Delete() and DataRow.Remove()?

729






How to count groups returned with the group by clause in ms sql server?

556


Why SQL Agent is used?

594


How many types of dimensions are there and what are they? : sql server analysis services, ssas

560


Differentiate between SQL and ORACLE joins and write their syntax.

587


How you trouble shoot when any job fails

1502


How do you make a trace?

580


What are the limitations/drawbacks or ssrs 2008 r2?

86


List the different normalization forms?

536


How many tables can be joined in SQL Server?

590


How each E-R model constructs can be mapped to the relational model?

553