Sunday, 27 July 2014

What is Trigger in SQL Server

Trigger:

             A Trigger is a database object similar to a stored procedure that executes in response to certain actions that occur in your database environment.

Triggers are 2 types:

     1. After trigger(For trigger)
     2.Instead of Trigger

After trigger(For trigger):

           After trigger are stored procedures that occurs after a data manipulation statement has occurred in the database, such as a delete statement.

Instead of Trigger:

         Instead of Trigger are objects that will execute instead of data manipulation statements in database engine. 
For example, attaching an INSTEAD-OF INSERT trigger will tell the the database to engine to execute that trigger instead of executing that  statement that would insert values into that table.

Syntax: 

CREATE TRIGGER trigger_name
ON {table| view}
[WITH ENCRYPTION]
{{AFTER|FOR | INSTEAD OF | }{[INSERT][,][DELETE] [UPDATE]}
AS
         sql_statement[....n]
}
}


No comments:

Post a Comment