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

Triggers

Triggers are stored procedures that automatically execute when data changes occur in a database. There are two types of triggers: DML triggers that fire on data manipulation language statements like insert, update, delete; and DDL triggers that fire on data definition language statements like create, alter, drop. Triggers specify a trigger name, timing (before or after the triggering statement), and event (insert, update, delete). They can run for each row affected or once per statement. Triggers provide advantages like ensuring data integrity and automating tasks, but also have disadvantages like complexity, performance overheads, and debugging challenges.

Uploaded by

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

Triggers

Triggers are stored procedures that automatically execute when data changes occur in a database. There are two types of triggers: DML triggers that fire on data manipulation language statements like insert, update, delete; and DDL triggers that fire on data definition language statements like create, alter, drop. Triggers specify a trigger name, timing (before or after the triggering statement), and event (insert, update, delete). They can run for each row affected or once per statement. Triggers provide advantages like ensuring data integrity and automating tasks, but also have disadvantages like complexity, performance overheads, and debugging challenges.

Uploaded by

murad25.cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

TRIGGERS

Md. Arafatuzzaman
Student ID: 200140​
WHAT IS TRIGGERS?

•Definition: Triggers are a special type of Stored


Procedure in a database management system that
automatically initiates an action when a certain
event occurs.
TYPES OF TRIGGERS

•DML Triggers: These triggers fire in response to Data Manipulation


Language (DML) statements like INSERT, UPDATE, DELETE.

•DDL Triggers: These triggers respond to Data Definition Language (DDL)


statements like CREATE, ALTER, or DROP.
4
5

 Trigger_name
-Is the name of the trigger.
 Before | after
-before indicates that the trigger should be fired before the
trigger statement.
-after indicates that the trigger should be fired after the trigger
statement.
 Delete | Insert | Update
- Delete indicates that the trigger statement deletes a row.
- Insert indicates that the trigger statement Insert a row.
- Update indicates that the trigger statement Update a row.
 For each row
- If this used, the trigger is fired for each row that the triggering
statement affects. If it is omitted, the trigger works only once
per statement.
Presentation title 6

Example 1 Example 2
7

Example 3

CREATE TABLE employees (


employee_id INT PRIMARY KEY,
employee_name VARCHAR(50),
total_salary INT
);

CREATE TABLE salary (


salary_id INT PRIMARY KEY,
employee_id INT,
salary_amount INT,
FOREIGN KEY (employee_id) REFERENCES
employees(employee_id)
);
ADVANTAGE
• Triggers ensure data consistency by enforcing constraints before
Data Integrity. inserting or updating data

• Triggers automate tasks, such as updating associated records or


Automation generating notifications, when specific events occur.

• Triggers can be used to create audit trails and log changes made to the
Auditing and Logging database for tracking and accountability purposes.

• Triggers enable the implementation of custom business rules and logic


Custom Business Logic. for specific data manipulation scenarios.

• Triggers facilitate immediate responses to database events, allowing


Immediate Actions. real-time updates or alerts when certain conditions are met.
DISADVANTAGE
Complexity and
Maintainability.

Performance Overheads

Debugging Challenges.

Invisible Logic.

Data Inconsistencies.

Testing Challenges.

Limited Portability.

Security Concerns.
THANK YOU…

You might also like