Tuesday 9 July 2013

Inserted Magic table with INSERT statement In sql sever

Hi,
     In this article we will see example of logical table or magic table when we insert data in sql table.

Example::

Suppose we have emp_info . Now We need to create two triggers to see data with
in logical tables Inserted and Deleted.

Step 1::Create Table

create table emp_info (empno int,ename varchar(100),manage_id int)

Step 2 :: CREATE TRIGGER on emp_info


CREATE TRIGGER trg_Emp_Ins
ON emp_info
FOR INSERT
AS
begin
SELECT * FROM INSERTED -- show data in Inserted logical table
SELECT * FROM DELETED -- show data in Deleted logical table
end

Step 3::Now insert a new record in emp_info table to see data with in Inserted logical table.


INSERT INTO emp_info(empno, ename, manage_id) VALUES(3,'Sandip G',3)
SELECT * FROM emp_info


     I hope You got something useful in this article.I would like to have feedback from my blog readers.
Your valuable feedback, question, or comments about this article are always welcome.

Other Popular Posts ::

No comments:

Post a Comment

if you have any doubt any suggestions do comment