Basic Trigger Example

/*Create or edit a trigger */
CREATE/ALTER TRIGGER triggerName
ON [sourceTableName]
FOR INSERT/UPDATE/DELETE
AS
Begin
    INSERT INTO targerTableName(column1 [,column2]) 
    SELECT i.column1 [,i.column2]   /* d.column1  (if you want to preserve prev value)*/
    FROM Inserted i                 /* FROM deleted d  */
End


/*Get list of triggers */
SELECT * FROM sys.triggers WHERE is_disabled = 0
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s