Sqlserver haveInserted and Deleted logical tables. These tables are automatically created and managed by SQL Server internally to hold recently inserted, deleted and updated values during DML operations (Insert,Update,Delete) on a database table.
Inserted logical Table
The Inserted table holds the recently inserted or updated values means new data values. Hence newly added and updated records are inserted into the Inserted table.
Suppose we have Employee table . Now We need to create two triggers to see data with in logical tables Inserted and Deleted.
CREATE TRIGGER TRIGGER_Employee_Insert
ON Employee
FOR INSERT
AS
begin
SELECT * FROM INSERTED -- show data in Inserted logical table
SELECT * FROM DELETED -- show data in Deleted logical table
end
Now insert a new record in Employee table to see data with in Inserted logical table.
The Deleted table holds the recently deleted or updated values means old data values. Hence old updated and deleted records are inserted into the Deleted table.
Create TRIGGER TRIGGER_Employee_Insert
ON Employee
FOR UPDATE
AS
begin
SELECT * FROM INSERTED -- show data in Inserted logical table
SELECT * FROM DELETED -- show data in Deleted logical table
end
--Now update the record in Employee
table to see data with in Inserted and Deleted logical tables
Update Employee set Emp_Sal=9200,Emp_Name='Shukla' where Emp_ID=7
SELECT*FROMEmployee
We could not create the logical tables or modify the data with in the logical tables. Except triggers, When you use the OUTPUT clause in your query, logical tables are automatically created and managed by SQL Server. OUTPUT clause also has access to Inserted and Deleted logical tables just like triggers.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Sqlserver have Inserted and Deleted logical tables. These tables are automatically created and managed by SQL Server internally to hold recently inserted, deleted and updated values during DML operations (Insert,Update,Delete) on a database table.
Inserted logical Table
The Inserted table holds the recently inserted or updated values means new data values. Hence newly added and updated records are inserted into the Inserted table.
Suppose we have Employee table . Now We need to create two triggers to see data with in logical tables Inserted and Deleted.
Now insert a new record in Employee table to see data with in Inserted logical table.
Deleted logical Table
The Deleted table holds the recently deleted or updated values means old data values. Hence old updated and deleted records are inserted into the Deleted table.
We could not create the logical tables or modify the data with in the logical tables. Except triggers, When you use the OUTPUT clause in your query, logical tables are automatically created and managed by SQL Server. OUTPUT clause also has access to Inserted and Deleted logical tables just like triggers.