SlideShare a Scribd company logo
Unlocking the Power
of Triggers in
SQL Server
support@nareshit.com
FOR MORE INFORMATION
https://nareshit.com/courses/sql-server-online-training
Agenda
Title Slide
Introduction to Triggers
Types of Triggers in SQL
Server
DDL Triggers
How to Create a Trigger
Logon Triggers
DML Triggers
Benefits & Drawbacks of
Triggers
Conclusion
Trigger Example
Title Slide
"Understanding Triggers in SQL Server"
Sets the focus on explaining the concept of triggers in SQL Server.
"A Comprehensive Overview"
Indicates a detailed exploration of the topic.
Your Name / Date:
Add your name and the presentation date for professionalism.
Example: John Doe | October 2, 2024.
Design:
Simple, professional background with bold fonts, and optionally a small
database icon or SQL Server logo.
Introduction to Triggers
Definition: A trigger is a special type of stored procedure that
automatically executes when an event occurs in the database.
Events: INSERT , UPDATE , DELETE
Purpose: To enforce business rules, automate tasks, and maintain data
integrity.
Types of Triggers in
SQL Server
1. DML Triggers: Triggered by INSERT , UPDATE, or DELETE.
2. DDL Triggers: Triggered by CREATE, ALTER , DROP
3. Logon Triggers: Triggered by user logon events.
Visual representation of the types.
DML Triggers
AFTER Trigger: Fires after the operation INSERT , UPDATE , DELETE
INSTEAD OF Trigger: Fires instead of the operation INSERT UPDATE
DELETE
Example use cases: Data validation, logging, cascading update
DDL Triggers
Fires on changes: To schema objects like tables, views, stored
procedures, etc.
Use Case: Preventing schema changes or auditing them.
Example: "Prevent a user from dropping a table."
03
https://nareshit.com/courses/sql-server-online-training
Logon Triggers
Fires on user login attempts.
Use Case: Restrict logins based on time, IP address, or security rules.
Example: Blocking login attempts during maintenance windows.
https://nareshit.com/courses/sql-server-online-training
How to Create a
Trigger
CREATE TRIGGER trigger_name
ON table_name
AFTER INSERT, UPDATE,DELETE
AS
BEGIN
-- Your SQL code here
END
Example of a simple AFTER INSERT trigger.
Syntax
CREATE TRIGGER trg_AfterInsert
ON Customers
AFTER INSERT
AS
BEGIN
-- INSERT INTO CustomerLog (CustomerID,
LogDate)
SELECT CustomerID, GETDATE() FROM inserted;
END
Trigger Example
Walk through the code and explain each part.
Scenario: Log changes in a Customers table
Benefits & Drawbacks
of Triggers
Benefits:
Automates repetitive tasks.
Enforces complex business rules.
Maintains data integrity.
Drawbacks:
Hidden logic, making debugging difficult.
Performance overhead if overused.
Potential for unintended consequences.
Conclusion
Summary:
Triggers are powerful for automating tasks and enforcing data rules.
They should be used carefully to avoid performance issues.
Best Practice: Keep triggers simple and well-documented.
https://nareshit.com/courses/sql-server-online-training
Get In Touch
Email
support@nareshit.com
Social Media
@nareshitech
Call us
8179191999
Thank you
nareshiTech
https://nareshit.com/courses/sql-server-online-training

More Related Content

PPTX
T-SQL & Triggers
PPTX
3130703_DBMS_GTU_Study_Material_Presentations_Unit-10_17102019083650AM.pptx
PPT
SQL Server 2008 Security Overview
PPTX
PLSQL.pptxokokokoo9oooodjdjfjfjfjrjejrjrrjrj
PDF
OTech magazine article - Principle of Least Privilege
PPT
Gerry Hughes Bi Portfolio
PPT
Sql tuning
PPT
Database Foundation Training
T-SQL & Triggers
3130703_DBMS_GTU_Study_Material_Presentations_Unit-10_17102019083650AM.pptx
SQL Server 2008 Security Overview
PLSQL.pptxokokokoo9oooodjdjfjfjfjrjejrjrrjrj
OTech magazine article - Principle of Least Privilege
Gerry Hughes Bi Portfolio
Sql tuning
Database Foundation Training

Similar to Unlocking the Power of Triggers in SQL Server (20)

PPTX
SQL Server - High availability
PPTX
DBMS UNIT 9.pptx..................................
PPT
Fortress SQL Server
PDF
Sherlock holmes for dba’s
PDF
Ms sql developer
PDF
Database Automation with MySQL Triggers and Event Schedulers
PPTX
10053 otw
ODP
SQL Tunning
PPT
Database Development Replication Security Maintenance Report
PPT
Sql security
PPT
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
PPT
Kevin Bengtson Portfolio
PPTX
Stored Procedures
PDF
Avoiding cursors with sql server 2005 tech republic
PPTX
Getting Started with MySQL II
PPTX
Using triggers in my sql database
PPTX
ISAS On SQL Features like Trigger, Transaction,Batches, Stored Procedure
PDF
Apex Enterprise Patterns: Building Strong Foundations
PPTX
NetBeans Day 2016 - Getting the best of NetBeans IDE
SQL Server - High availability
DBMS UNIT 9.pptx..................................
Fortress SQL Server
Sherlock holmes for dba’s
Ms sql developer
Database Automation with MySQL Triggers and Event Schedulers
10053 otw
SQL Tunning
Database Development Replication Security Maintenance Report
Sql security
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Kevin Bengtson Portfolio
Stored Procedures
Avoiding cursors with sql server 2005 tech republic
Getting Started with MySQL II
Using triggers in my sql database
ISAS On SQL Features like Trigger, Transaction,Batches, Stored Procedure
Apex Enterprise Patterns: Building Strong Foundations
NetBeans Day 2016 - Getting the best of NetBeans IDE
Ad

More from TejaswiniNareshIT (8)

PDF
React JS Online Course Training in NareshIT
PDF
Top 5 Reasons Why SQL Server in NareshIT
PDF
SQL Server Online Training in NareshIT.pdf
PDF
Data Types in C# OnlineTraining in Nareshit
PDF
Data Science and AI Introduction - NareshIT
PPTX
Different Types of Data Visualization.pptx
PDF
Different Types of Data Visualization in Data Science - NareshIT
PDF
important topics for data science - NareshIT
React JS Online Course Training in NareshIT
Top 5 Reasons Why SQL Server in NareshIT
SQL Server Online Training in NareshIT.pdf
Data Types in C# OnlineTraining in Nareshit
Data Science and AI Introduction - NareshIT
Different Types of Data Visualization.pptx
Different Types of Data Visualization in Data Science - NareshIT
important topics for data science - NareshIT
Ad

Recently uploaded (20)

PPTX
Lesson notes of climatology university.
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Complications of Minimal Access Surgery at WLH
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Classroom Observation Tools for Teachers
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Trump Administration's workforce development strategy
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
Lesson notes of climatology university.
Weekly quiz Compilation Jan -July 25.pdf
Cell Types and Its function , kingdom of life
Orientation - ARALprogram of Deped to the Parents.pptx
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Final Presentation General Medicine 03-08-2024.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
A systematic review of self-coping strategies used by university students to ...
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Complications of Minimal Access Surgery at WLH
Module 4: Burden of Disease Tutorial Slides S2 2025
Classroom Observation Tools for Teachers
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Trump Administration's workforce development strategy
History, Philosophy and sociology of education (1).pptx
Yogi Goddess Pres Conference Studio Updates
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Final Presentation General Medicine 03-08-2024.pptx

Unlocking the Power of Triggers in SQL Server

  • 1. Unlocking the Power of Triggers in SQL Server support@nareshit.com FOR MORE INFORMATION https://nareshit.com/courses/sql-server-online-training
  • 2. Agenda Title Slide Introduction to Triggers Types of Triggers in SQL Server DDL Triggers How to Create a Trigger Logon Triggers DML Triggers Benefits & Drawbacks of Triggers Conclusion Trigger Example
  • 3. Title Slide "Understanding Triggers in SQL Server" Sets the focus on explaining the concept of triggers in SQL Server. "A Comprehensive Overview" Indicates a detailed exploration of the topic. Your Name / Date: Add your name and the presentation date for professionalism. Example: John Doe | October 2, 2024. Design: Simple, professional background with bold fonts, and optionally a small database icon or SQL Server logo.
  • 4. Introduction to Triggers Definition: A trigger is a special type of stored procedure that automatically executes when an event occurs in the database. Events: INSERT , UPDATE , DELETE Purpose: To enforce business rules, automate tasks, and maintain data integrity.
  • 5. Types of Triggers in SQL Server 1. DML Triggers: Triggered by INSERT , UPDATE, or DELETE. 2. DDL Triggers: Triggered by CREATE, ALTER , DROP 3. Logon Triggers: Triggered by user logon events. Visual representation of the types.
  • 6. DML Triggers AFTER Trigger: Fires after the operation INSERT , UPDATE , DELETE INSTEAD OF Trigger: Fires instead of the operation INSERT UPDATE DELETE Example use cases: Data validation, logging, cascading update
  • 7. DDL Triggers Fires on changes: To schema objects like tables, views, stored procedures, etc. Use Case: Preventing schema changes or auditing them. Example: "Prevent a user from dropping a table." 03 https://nareshit.com/courses/sql-server-online-training
  • 8. Logon Triggers Fires on user login attempts. Use Case: Restrict logins based on time, IP address, or security rules. Example: Blocking login attempts during maintenance windows. https://nareshit.com/courses/sql-server-online-training
  • 9. How to Create a Trigger CREATE TRIGGER trigger_name ON table_name AFTER INSERT, UPDATE,DELETE AS BEGIN -- Your SQL code here END Example of a simple AFTER INSERT trigger. Syntax
  • 10. CREATE TRIGGER trg_AfterInsert ON Customers AFTER INSERT AS BEGIN -- INSERT INTO CustomerLog (CustomerID, LogDate) SELECT CustomerID, GETDATE() FROM inserted; END Trigger Example Walk through the code and explain each part. Scenario: Log changes in a Customers table
  • 11. Benefits & Drawbacks of Triggers Benefits: Automates repetitive tasks. Enforces complex business rules. Maintains data integrity. Drawbacks: Hidden logic, making debugging difficult. Performance overhead if overused. Potential for unintended consequences.
  • 12. Conclusion Summary: Triggers are powerful for automating tasks and enforcing data rules. They should be used carefully to avoid performance issues. Best Practice: Keep triggers simple and well-documented. https://nareshit.com/courses/sql-server-online-training
  • 13. Get In Touch Email support@nareshit.com Social Media @nareshitech Call us 8179191999