Algorithm to Create Trigger In SQL Server
In this article I describe algorithm to write trigger in SQL Server.
Trigger
Triggers in SQL are a special type of procedure that are executed, fired or invoked automatically in response to an action query are executed on a view or table.
Algorithm to Create Trigger In SQL Server
- CREATE [OR REPLACE ] TRIGGER trigger_name.
- {BEFORE | AFTER | INSTEAD OF }.
- {INSERT [OR] | UPDATE [OR] | DELETE}.
- [OF col_name].
- CREATE [OR REPLACE ] TRIGGER trigger_name.
- [ON table_name].
- [REFERENCING OLD AS o NEW AS n].
- [FOR EACH ROW].
- WHEN (condition).
where,
trigger_name specifies the name of trigger you want to give.
before/after/instead of specifies types of trigger.
insted/update/delete specifies after which operation trigger should be fired.
table_name specifies the table name on which trigger is applied.