Trigger In Sql
What is a Trigger?
A trigger is a pl/sql block structure which is fired when a DML
statements like Insert, Delete, Update is executed on a database
table. A trigger is triggered automatically when an associated DML
statement is executed.
Syntax of Triggers
Syntax for Creating a Trigger
CREATE [OR REPLACE ] TRIGGER trigger_name
{BEFORE | AFTER | INSTEAD OF }
{INSERT [OR] | UPDATE [OR] | DELETE}
[OF col_name]
ON table_name
[REFERENCING OLD AS o NEW AS n]
[FOR EACH ROW]
WHEN (condition)
BEGIN
--- sql statements
END;
CREATE [OR REPLACE ] TRIGGER trigger_name - This clause creates a
trigger with the given name or overwrites an existing trigger with the
same name.
{BEFORE | AFTER | INSTEAD OF } - This clause indicates at what
time should the trigger get fired. i.e for example: before or after
updating a table. INSTEAD OF is used to create a trigger on a view.
before and after cannot be used to create a trigger on a v