Triggers:
============== SQL Server 2005=====================
IF OBJECT_ID ('dbo.trEmployee', 'TR') IS NOT NULL
DROP TRIGGER dbo.trEmployee
GO
CREATE TRIGGER trEmployee
ON Practice.dbo.Employee
AFTER INSERT, UPDATE
AS
update employee set triggerdate=getdate()
GO
=============================================
============== SQL Server 2000=====================
IF OBJECT_ID ('Sales.reminder1', 'TR') IS NOT NULL
DROP TRIGGER Sales.reminder1
GO
CREATE TRIGGER reminder1
ON Sales.Customer
AFTER INSERT, UPDATE
AS RAISERROR ('Notify Customer Relations', 16, 10)
GO
============================================
In the above Two examples 'Sales.reminder1' where as ‘Sales’ is the Database and ‘reminder1’ is the table name and 'TR' is the Trigger.The object_ID will return the integer.If any trigger is there You are telling to drop the trigger and then Create trigger triggername on (databaseobject(dbo).table) this is in sql server 2005 and (database.table) this is in sql server 2000.After the which event u want to fire the trigger like insert,update(dml) as where u want to save the trigger in the table.
Here the result after the update or insert the trigger event will fire and save in to system triggers in the same table.
No comments:
Post a Comment