0% found this document useful (0 votes)
30 views10 pages

SQL Triggers

SQL triggers are stored procedures that automatically execute in response to specific events on a table, ensuring data consistency and reducing application-side logic. They can be categorized by timing (BEFORE, AFTER, INSTEAD OF) and events (INSERT, UPDATE, DELETE), serving purposes such as automating tasks, maintaining audit trails, and enforcing business rules. Triggers help in tracking data changes and maintaining data integrity across tables.

Uploaded by

luy.allain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views10 pages

SQL Triggers

SQL triggers are stored procedures that automatically execute in response to specific events on a table, ensuring data consistency and reducing application-side logic. They can be categorized by timing (BEFORE, AFTER, INSTEAD OF) and events (INSERT, UPDATE, DELETE), serving purposes such as automating tasks, maintaining audit trails, and enforcing business rules. Triggers help in tracking data changes and maintaining data integrity across tables.

Uploaded by

luy.allain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL

TRIGGERS
GROUP 3 - BSIT 2R13
WHAT ARE SQL TRIGGERS?

SQL SQL TRIGGER

Structured Query Are stored procedures


Language for that automatically
managing relational execute in response to
databases. certain events.
SQL TRIGGER
A trigger is a set of SQL statements that execute
automatically in response to certain table events.
Triggers enable automatic responses to data changes,
ensuring consistency and reducing the need for
application-side logic.
PURPOSE & BENEFITS OF
TRIGGERS

Automate Improve
Maintain
System Data
Audit Trails
Tasks Integrity
SQL Trigger Syntax

Components:
‘BEFORE` / `AFTER` / `INSTEAD OF`: Timing of execution.
`INSERT`, `UPDATE`, `DELETE`: Event type.
`FOR EACH ROW`: Row-level execution.
Types of Triggers
1. TRIGGERS BASED ON TIMING

BEFORE AFTER INSTEAD OF


Executes before the Executes after the Replaces the normal
triggering event. triggering event. execution of the event.
Used to validate or Used for logging or Mainly used on views to
modify incoming data. post-processing tasks. customize behavior.
Types of Triggers
1. TRIGGERS BASED ON EVENTS

INSERT UPDATE DELETE


Executes when a new Executes when an Executes when a row is
row is added to a table. existing row is modified. removed from a table.
Useful for initializing Commonly used for Often used to archive
values or updating tracking changes or data or maintain
related records. enforcing business logic. referential integrity.
Automate Repetitive
01 Tasks

Track and Log Data


02
WHEN TO USE Changes

TRIGGERS? Enforce Business Rules


03
Beyond Constraints

04 Maintain Data
Consistency Across
Tables
Trigger Example
Automatically Updating Product Stock After a Sale (AFTER
INSERT Trigger)
THANK YOU!

You might also like