Embed presentation
Download to read offline

![Triggers
• Named SQL blocks Which are Stored in Database
• Specialized Stored Proggrams which execute implicitly
• when a triggering event occurs
• 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.](https://image.slidesharecdn.com/triggers-180122044606/75/Triggers-2-2048.jpg)


![Syntax
CREATE TRIGGER <triggerName>
BEFORE|AFTER INSERT|DELETE|UPDATE
[OF <columnList>] ON
<tableName>|<viewName>
[REFERENCING [OLD AS <oldName>] [NEW AS
<newName>]]
[FOR EACH ROW] (default is “FOR EACH STATEMENT”)
[WHEN (<condition>)]
<PSM body>;](https://image.slidesharecdn.com/triggers-180122044606/75/Triggers-5-2048.jpg)


Triggers are stored programs that automatically execute when a triggering event occurs, like an insert, update, or delete statement or a system event. They have three parts - an event that activates the trigger, an optional condition to check if the trigger should run, and an action that specifies what code is executed. Common trigger types include DML triggers for data modification statements, DDL triggers for data definition statements, and logon triggers. Triggers are defined using CREATE TRIGGER syntax and can check for and prevent actions like decreasing a salary value.

![Triggers
• Named SQL blocks Which are Stored in Database
• Specialized Stored Proggrams which execute implicitly
• when a triggering event occurs
• 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.](https://image.slidesharecdn.com/triggers-180122044606/75/Triggers-2-2048.jpg)


![Syntax
CREATE TRIGGER <triggerName>
BEFORE|AFTER INSERT|DELETE|UPDATE
[OF <columnList>] ON
<tableName>|<viewName>
[REFERENCING [OLD AS <oldName>] [NEW AS
<newName>]]
[FOR EACH ROW] (default is “FOR EACH STATEMENT”)
[WHEN (<condition>)]
<PSM body>;](https://image.slidesharecdn.com/triggers-180122044606/75/Triggers-5-2048.jpg)

