What are TRIGGERS in SQL Server

 


TRIGGERS are stored program/ special stored procedure that execute automatically in response to database object, database, and server events.

For example, a trigger can be invoked when a row is deleted or inserted.

Types of Triggers:
  1. DDL TRIGGERS: which fires/ triggers in response to CREATE, ALTER, and DROP statements. 
  2. DML TRIGGERS: which are invoked automatically in response to INSERT, UPDATE, and DELETE commands.
  3. LOGON TRIGGERS: Invokes only in responses to LOGON events.

SYNTAX:

CREATE TRIGGER:

 

CREATE TRIGGER [SCHEMANAME].TRIGGER_NAME

ON TABLE_NAME

AFTER {

        [INSERT],

           [UPDATE],

           [DELETE]

       }

AS

{

       //YOUR CODE

}

 

 

DROP TRIGGER


 

DROP TRIGGER [IF EXISTS]

[SCHEMA_NAME].TRIGGER_NAME


DROP TRIGGER statement drops one or more triggers from the database.






Post a Comment

0 Comments