SQL Advanced (Triggers)
SQL Advanced (Triggers)
SQL Advanced (Triggers)
TRIGGERS
IN
SQL
SHVETA MAINI
1
What is Trigger?
.
A trigger is a stored procedure in a
database that automatically invokes
whenever a special event in the database
occurs.
.
Explanation Of Syntax
CREATE TRIGGER trigger_name: Defines a new
trigger.
{BEFORE | AFTER | INSTEAD OF}: Specifies
when the trigger should fire (before, after, or
instead of the operation).
{INSERT | UPDATE | DELETE}: Specifies which
data modification event will activate the
trigger.
ON table_name: Specifies the table the trigger
is associated with.
[FOR EACH ROW]: (Optional) Specifies that the
trigger should execute for each affected row.
BEGIN ... END: The block where the SQL
actions to be executed by the trigger are
placed.
4
TYPES OF TRIGGER:-
5
(1.) AUTOMATION:-
.
Triggers automate tasks such as logging,
validating, or updating related tables
without requiring manual intervention.
(3.)
. REAL TIME EXECUTION:-
Triggers are event-driven, meaning they
execute immediately after a specified
event occurs. This ensures that the related
operations are always synchronized with
the data changes.
BEST PRACTICES
.
Keep Triggers Simple: Complex trigger
logic can lead to performance
problems and debugging difficulties.
Keep the logic inside triggers as
simple as possible.