Monday, 20 January 2014

Simple trigger in sql server 2008 R2

CREATE TRIGGER trig_Insert_Employee
ON Emp
FOR INSERT
AS
Begin
    Insert into dbo.backtable (id, insertdate)   select MAX(id),GETDATE() from Emp
    
End



here
Emp is table name , whenever emp table gets insert the trigger will get fired! 





























insert into Emp(id,name) values(2,'First')


select * from sys.objects where type='TR'

The above query will display the triggers in database. and it holds parent object id.

No comments:

Post a Comment