SlideShare a Scribd company logo
Triggers in SQL | Edureka
WHAT IS A TRIGGER?
SYNTAX AND EXAMPLE
OPERATION ON TRIGGERS
ADVANTAGES AND DISADVANTAGES
www.edureka.co
www.edureka.co
Triggers are the SQL codes that are automatically executed in response to certain events on a
particular table. These are used to maintain the integrity of the data.
What is a TRIGGER?
www.edureka.co
WHAT IS A TRIGGER?
Hey Sharan, Do you
know what Triggers
are?
www.edureka.co
WHAT IS A TRIGGER?
www.edureka.co
Well, Let me explain
you in a simple way
www.edureka.co
PROBLEM WITHOUT TRIGGER
www.edureka.co
PROBLEM WITHOUT TRIGGER
www.edureka.co
PROBLEM WITHOUT TRIGGER
www.edureka.co
PROBLEM WITHOUT TRIGGER
www.edureka.co
PROBLEM WITHOUT TRIGGER
www.edureka.co
PROBLEM WITHOUT TRIGGER
www.edureka.co
PROBLEM WITHOUT TRIGGER
www.edureka.co
PROBLEM WITHOUT TRIGGER
www.edureka.co
SOLUTION
www.edureka.co
SOLUTION
www.edureka.co
SOLUTION
www.edureka.co
SOLUTION
www.edureka.co
SOLUTION
www.edureka.co
www.edureka.co
SYNTAX
OF TRIGGER
www.edureka.co
Create Trigger Trigger_Name
(Before | After)
[ Insert | Update | Delete]
on [Table_Name]
[ for each row | for each column ]
[ Trigger_body ]
EXAMPLE
OF TRIGGER
CREATE TRIGGER sample_trigger
before INSERT
ON student
FOR EACH ROW
SET new.marks = new.marks+6;
www.edureka.co
NESTED TRIGGERS
www.edureka.co
Nested Triggers in
SQL are the actions
that automatically
executed when a
certain database
operation is
performed
www.edureka.co
www.edureka.co
SYNTAX:
DROP TRIGGER trigger name;
EXAMPLE:
DROP TRIGGER calculate name;
We can use DROP
command to remove a
trigger from the
database
DROP
www.edureka.co
We can use SHOW
command to display
triggers from the
database
DISPLAY
SYNTAX:
SHOW TRIGGERS
IN database_name;
EXAMPLE:
SHOW TRIGGERS
IN edureka;
www.edureka.co
SYNTAX:
CREATE TRIGGER calculate
before INSERT
ON student
FOR EACH ROW
SET new.marks = new.marks+100;
Before Insert
Triggers are used
to update or
validate record
values before
they’re saved to
the database
INSERT
www.edureka.co
SYNTAX:
CREATE TRIGGER total_mark
after insert
ON student
FOR EACH ROW
insert into Final_mark values(new.marks);
After Insert
Triggers are used
to access field
values that are set
by the system and
to effect changes
in other records
INSERT
www.edureka.co
ADVANTAGES OF TRIGGERS
02
Triggers check the
integrity of data
01
Forcing security
approvals on the
table
03
Counteracting
invalid exchanges
04
Triggers handle
errors
05
Triggers are useful for
inspecting the data
www.edureka.co
DISADVANTAGES OF TRIGGERS
Overhead
Triggers may increase
the overhead of the
database
Validation
Triggers can only
provide extended
validations, i.e, not
all kind validations
Troubleshoot
Triggers can be difficult
to troubleshoot because
they execute
automatically in the
database
www.edureka.co
www.edureka.co

More Related Content

What's hot (20)

PDF
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
PPT
Joins in SQL
Vigneshwaran Sankaran
 
PPTX
8. transactions
Amrit Kaur
 
PPTX
SQL Commands
Sachidananda M H
 
PPT
1 - Introduction to PL/SQL
rehaniltifat
 
PPTX
Joins And Its Types
Wings Interactive
 
PPT
Database Triggers
Aliya Saldanha
 
PPTX
5. stored procedure and functions
Amrit Kaur
 
PPTX
Sql subquery
Raveena Thakur
 
PPTX
SQL Basics
Hammad Rasheed
 
PPTX
Triggers
Pooja Dixit
 
PPTX
Sql fundamentals
Ravinder Kamboj
 
PPTX
Sql Constraints
I L0V3 CODING DR
 
PPT
Sql operators & functions 3
Dr. C.V. Suresh Babu
 
ODP
Sql commands
Balakumaran Arunachalam
 
PDF
View & index in SQL
Swapnali Pawar
 
PDF
SQL Joins With Examples | Edureka
Edureka!
 
PPT
PL/SQL
Vaibhav0
 
PPTX
Group By, Having Clause and Order By clause
Deepam Aggarwal
 
PPTX
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
Joins in SQL
Vigneshwaran Sankaran
 
8. transactions
Amrit Kaur
 
SQL Commands
Sachidananda M H
 
1 - Introduction to PL/SQL
rehaniltifat
 
Joins And Its Types
Wings Interactive
 
Database Triggers
Aliya Saldanha
 
5. stored procedure and functions
Amrit Kaur
 
Sql subquery
Raveena Thakur
 
SQL Basics
Hammad Rasheed
 
Triggers
Pooja Dixit
 
Sql fundamentals
Ravinder Kamboj
 
Sql Constraints
I L0V3 CODING DR
 
Sql operators & functions 3
Dr. C.V. Suresh Babu
 
View & index in SQL
Swapnali Pawar
 
SQL Joins With Examples | Edureka
Edureka!
 
PL/SQL
Vaibhav0
 
Group By, Having Clause and Order By clause
Deepam Aggarwal
 
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
PDF
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
PDF
Tableau Tutorial for Data Science | Edureka
Edureka!
 
PDF
Python Programming Tutorial | Edureka
Edureka!
 
PDF
Top 5 PMP Certifications | Edureka
Edureka!
 
PDF
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
PDF
Linux Mint Tutorial | Edureka
Edureka!
 
PDF
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
PDF
Importance of Digital Marketing | Edureka
Edureka!
 
PDF
RPA in 2020 | Edureka
Edureka!
 
PDF
Email Notifications in Jenkins | Edureka
Edureka!
 
PDF
EA Algorithm in Machine Learning | Edureka
Edureka!
 
PDF
Cognitive AI Tutorial | Edureka
Edureka!
 
PDF
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
PDF
Blue Prism Top Interview Questions | Edureka
Edureka!
 
PDF
Big Data on AWS Tutorial | Edureka
Edureka!
 
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
PDF
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
PDF
Introduction to DevOps | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Edureka!
 
Ad

Recently uploaded (20)

PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Digital Circuits, important subject in CS
contactparinay1
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Ad

Triggers in SQL | Edureka