Trigger
Trigger
Trigger
• A trigger is a stored procedure in database which
automatically invokes whenever a special event occurs
in the database.
• A procedure that starts automatically if
specified changes occur to the DBMS.
• For example, a trigger can be invoked when a row is
inserted into a specified table or when certain table
columns are being updated.
Example: 1
Triggers (Active database)
• Three parts:
– Event (activates the trigger)
– Condition (tests whether the triggers should run)
[Optional]
– Action (what happens if the trigger runs)
• Semantics:
– When event occurs, and condition is satisfied, the
action is performed.
Triggers – Event,Condition,Action
• Eventscould be :
BEFORE|AFTER INSERT|UPDATE|DELETE ON <tableName>
END;
Example Trigger
END;
Example Trigger
CREATE TRIGGER minSalary BEFORE INSERT ON
Professor
FOR EACH ROW
BEGIN
BEGIN
RAISE_APPLICATION_ERROR (-20004,
‘Violation of Minimum Professor Salary’);
END;
Example Trigger