Triggers In SQL| Triggers In Database | SQL Triggers Tutorial For Beginners | Edureka Rewind

edureka! · Beginner ·📊 Data Analytics & Business Intelligence ·2y ago

Key Takeaways

Explains SQL triggers, including their concept, usage, and implementation in database management

Full Transcript

hey guys this is prati from edu Rea and I welcome you all to this interesting session on triggers in SQL but before we get started let's have a look at the agenda for today's session so we're going to begin with understanding what is a trigger followed by that we'll be looking at its syntax and example next up let's try to get the detailed explanation on various operations that can be performed using trigger and finally we'll wrap up this session by discussing its advantages and disadvantages so I hope the agenda is clear you guys so with that being said let's get started the first Topic in today's discussion is what are triggers triggers are the SQL code that are automatically executed in response to certain events on a particular table these are used to maintain the Integrity of the data in a given table a trigger in SQL Works similar to real world trigger I know this is a formal definition but let's try to understand it in a better way here we can see Anna is asking Sharon about triggers Sharon imagines trigger to a falling dominoes how does a falling dominoes is related to a trigger let's move further and see the explanation given by Sharon Anna is a marketing officer in a company when a new customer data is entered into the company's database she has to send the welcome email to each and every new customer if it is one or two customer Anna can do it manually but what if the count is more than a th000 it will be a repetitive and tiring job efficiency of Anna may drop well in such scenario triggers come in handy Anna can easily create a trigger which will automatically send a welcome email to new customer once the data is enter into the database after creating a trigger in the database of the company she doesn't have to monitor the trigger frequently the efficiency of the work is increased with this analogy given by Sharon I hope you're clear with the introduction of trigger let's head to the next topic that is syntax and example of a trigger on the screen we can see the syntax of a trigger and let me explain each and every part in detail the first part is create trigger these two keywords are used to specify that a trigger block is going to be declared the next one is trigger name it specifies the name of the trigger trigger name has to be unique and shouldn't repeat the next one is before or after this specifies when the trigger will be executed it tells us the time at which the trigger is initiated that is either before ongoing event or after the ongoing event before triggers are used to update or validate record values before they are saved to the database while after triggers are used to access Fields values that are sent by the system and to affect changes in other records the records that activate the after trigger are read only we cannot use after trigger if we want to update a record because it will lead to a readon error the next part of the syntax is insert update or delete these are the DML operations and we can use either of them in a given trigger next is on table name we need to mention the table name on which the trigger is being applied don't forget to use on keyword and also so make sure the select before or after any column value of a row changes while column level triggers get executed before or after the specified column changes the final part of the syntax consists of queries that needs to be executed for a trigger in the given trigger we are trying to calculate the marks of a student as soon as his details are updated to the database here we are adding 100 marks to the marks column of of each new record also make a note new keyword refers to the row that is getting affected so this was all about a simple trigger but we can also create a nester trigger that can do multiple process also handling it and terminating it at the right time is very important if you don't end the trigger properly it may lead to an infinite Loop you might be wondering in which scenario we can use the nested trigger rather than giving you a tailored answer let me share a scenario with you which will help you in understanding the N trigger in a better way continuing from the earlier scenario Anna sent an email for every new customer that was added to the company's database now what if she wishes to keep a track of numbers of customers to whom the email was sent now Anna needs to create a nested trigger to keep the track of the count along with sending an email doesn't it sound simple so that was all about the syntax of trigger let's now try to implement an example of trigger in SQL so the next topic is operations in trigger we can perform many operations using triggers some may be simple and some may be little complex but once if we go through the query it's easy to understand the first operation is drop we can use drop command to remove a trigger from the database and the Syntax for this is drop trigger trigger name to understand this in a better way let's head to my SQL workbench I hope you know how to use my SQL workbench if not then check SQL basics for beginner video by edura for better understanding of how my SQL workbench will work to drop a trigger from the database the trigger has to be present present in our database so this is a syntax used to drop a trigger so let me execute this query so we can see in the status bar the trigger with the name sample trigger has been dropped let's head to the next operation that is display we can use show command to display the triggers from the database and the Syntax for this is show triggers in database name so let me head back to my SQL workbench to execute this command to display a trigger the trigger has to be present in the database so let me execute this SQL query to display the triggers that are present in my database I can see that the trigger with the name sample trigger is present in my database edura so let's head to the next operation the next operation is insert and the first variant is before insert triggers before insert triggers are used to update or validate record values before they save to database and the Syntax for this is create trigger calculate here calculate is the name of the trigger before insert on the table name for each row and set operation so let me head back to my SQL workbench to execute this query before explaining before insert trigger let me explain something else I will be using student table and The Columns of this table are it has student ID first name last name address City and marks I will be creating a trigger with the name sample trigger here before insert trigger is used to set 100 marks extra for each and every student marks column when the new student value is added to the table so let me execute this trigger and we can see that the trigger has been created now let me insert a record into the table I'll be using insert into command to insert a record into the table so let me execute this query but before that make sure to remember I will be adding details of wami K his marks will be 478 but as we have created a trigger it has to add 100 marks extra and the resulting marks has to be 578 so let me execute this query okay the query has been inserted so let me check the table and we can see that the marks of wami K is 578 so we can clearly say that the trigger has worked so the next variant of insert is after insert triggers after insert triggers are used to access Fields values that are set by the system and to affect changes in other records and the syntax is create trigger name of the trigger that is total Mark after insert on student student is a table name for each row insert into final marks value of the column so let's head back to my SQL workbench to execute this example to use this variant we need one more table that is final marks table where the trigger will store the results this SQL query will create a table with the name final marks so let me execute this query so we can see in the status bar the table with the name final marks has been created whenever we insert data to student table the previous trigger that is sample trigger will be executed now with the help of after insert trigger let's store the marks of the student table in the final Mark table this will be the after insert trigger and the name of this trigger is scal we will be updating total marks from student table to final marks table let me execute this trigger and we can see that the trigger with the name Cal has been created to check the working of a trigger named Cal let me insert the data of rajit Kumar into student table and make a note his marks is 500 so we can see that the data has been inserted into the student table let me execute this query and we can see that the student name rajit Kumar has 600 marks let's move to the next topic that is advantage and disadvantage let's look at the advantages of a trigger first one is forcing security approvals on the table that are present in the database the next one is triggers provide another way to check the Integrity of the data the third one is triggers counter react invalid exchanges the fourth one is triggers handle errors from the database layer and the final one is normally triggers can be useful for inspecting the data changes in the table let's look at the disadvantage of a trigger triggers can only provide extended validation that is not all kind of validations for simple validations you cannot use Nal unique check and foreign key constraints in a given trigger the next one is triggers may increase the overate of a database and the final disadvantage is triggers can be difficult to troubleshoot because they execute automatically in the database this may not be visible to client applications this brings us to the end of this trigger in SQL session I hope you understood the concepts of trigger that's all from my side for today's session thank you and have a great day

Original Description

🔥 𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐎𝐧𝐥𝐢𝐧𝐞 𝐌𝐲𝐒𝐐𝐋 𝐃𝐁𝐀 𝐂𝐞𝐫𝐭𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐓𝐫𝐚𝐢𝐧𝐢𝐧𝐠 : https://www.edureka.co/mysql-dba (Use Code "𝐘𝐎𝐔𝐓𝐔𝐁𝐄𝟐𝟎") This Edureka video on 'SQL Triggers' will help you understand the concept of triggers in SQL. 📢📢 𝐓𝐨𝐩 𝟏𝟎 𝐓𝐫𝐞𝐧𝐝𝐢𝐧𝐠 𝐓𝐞𝐜𝐡𝐧𝐨𝐥𝐨𝐠𝐢𝐞𝐬 𝐭𝐨 𝐋𝐞𝐚𝐫𝐧 𝐢𝐧 𝟐𝟎𝟐𝟒 𝐒𝐞𝐫𝐢𝐞𝐬 📢📢 ⏩ NEW Top 10 Technologies To Learn In 2024 - https://www.youtube.com/watch?v=vaLXPv0ewHU 🔴 Subscribe to our channel to get video updates. Hit the subscribe button above: https://goo.gl/6ohpTV 🔴 𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐎𝐧𝐥𝐢𝐧𝐞 𝐓𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐚𝐧𝐝 𝐂𝐞𝐫𝐭𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧𝐬 🔵 DevOps Online Training: http://bit.ly/3VkBRUT 🌕 AWS Online Training: http://bit.ly/3ADYwDY 🔵 React Online Training: http://bit.ly/3Vc4yDw 🌕 Tableau Online Training: http://bit.ly/3guTe6J 🔵 Power BI Online Training: http://bit.ly/3VntjMY 🌕 Selenium Online Training: http://bit.ly/3EVDtis 🔵 PMP Online Training: http://bit.ly/3XugO44 🌕 Salesforce Online Training: http://bit.ly/3OsAXDH 🔵 Cybersecurity Online Training: http://bit.ly/3tXgw8t 🌕 Java Online Training: http://bit.ly/3tRxghg 🔵 Big Data Online Training: http://bit.ly/3EvUqP5 🌕 RPA Online Training: http://bit.ly/3GFHKYB 🔵 Python Online Training: http://bit.ly/3Oubt8M 🌕 Azure Online Training: http://bit.ly/3i4P85F 🔵 GCP Online Training: http://bit.ly/3VkCzS3 🌕 Microservices Online Training: http://bit.ly/3gxYqqv 🔵 Data Science Online Training: http://bit.ly/3V3nLrc 🌕 CEHv12 Online Training: http://bit.ly/3Vhq8Hj 🔵 Angular Online Training: http://bit.ly/3EYcCTe 🔴 𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐑𝐨𝐥𝐞-𝐁𝐚𝐬𝐞𝐝 𝐂𝐨𝐮𝐫𝐬𝐞𝐬 🔵 DevOps Engineer Masters Program: http://bit.ly/3Oud9PC 🌕 Cloud Architect Masters Program: http://bit.ly/3OvueZy 🔵 Data Scientist Masters Program: http://bit.ly/3tUAOiT 🌕 Big Data Architect Masters Program: http://bit.ly/3tTWT0V 🔵 Machine Learning Engineer Masters Program: http://bit.ly/3AEq4c4 🌕 Business Intelligence Masters Program: http://bi
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from edureka! · edureka! · 0 of 60

← Previous Next →
1 ChatGPT Not Working - 4 Fixes | How To Fix ChatGPT Not Working | Why Is ChatGPT Not Working |Edureka
ChatGPT Not Working - 4 Fixes | How To Fix ChatGPT Not Working | Why Is ChatGPT Not Working |Edureka
edureka!
2 Advanced Java script Tutorial | JavaScript Training | JavaScript Programming | Edureka Rewind
Advanced Java script Tutorial | JavaScript Training | JavaScript Programming | Edureka Rewind
edureka!
3 Java script interview question and answers | Java script training | Edureka Rewind
Java script interview question and answers | Java script training | Edureka Rewind
edureka!
4 OpenAI API Tutorial using Python | How to use OpenAI GPT-3 API - Ada Babbage Curie Davinci | Edureka
OpenAI API Tutorial using Python | How to use OpenAI GPT-3 API - Ada Babbage Curie Davinci | Edureka
edureka!
5 What is Unsupervised Learning ? | Unsupervised Learning Algorithms| Machine Learning | Edureka
What is Unsupervised Learning ? | Unsupervised Learning Algorithms| Machine Learning | Edureka
edureka!
6 Top 10 Applications of Machine Learning in 2023 | Machine Learning  Training | Edureka Rewind - 7
Top 10 Applications of Machine Learning in 2023 | Machine Learning Training | Edureka Rewind - 7
edureka!
7 Machine Learning Engineer Career Path in 2023  | Machine Learning Tutorial | Edureka Rewind - 6
Machine Learning Engineer Career Path in 2023 | Machine Learning Tutorial | Edureka Rewind - 6
edureka!
8 10 Must Have Machine Learning Engineer Skills That Will Get You Hired   | Edureka Rewind - 7
10 Must Have Machine Learning Engineer Skills That Will Get You Hired | Edureka Rewind - 7
edureka!
9 Data Structures in Python | Data Structures and Algorithms in Python | Edureka | Python Live - 5
Data Structures in Python | Data Structures and Algorithms in Python | Edureka | Python Live - 5
edureka!
10 Python Lists | List in Python | Python Training  | Edureka  Rewind
Python Lists | List in Python | Python Training | Edureka Rewind
edureka!
11 Predictive Analysis Using Python | Learn to Build Predictive Models | Python Training | Edureka
Predictive Analysis Using Python | Learn to Build Predictive Models | Python Training | Edureka
edureka!
12 Machine Learning Tutorial | Machine Learning Algorithm | Machine Learning Engineer Program | Edureka
Machine Learning Tutorial | Machine Learning Algorithm | Machine Learning Engineer Program | Edureka
edureka!
13 How to use Pandas in Python | Python Pandas Tutorial  | Python Tutorial  |  Edureka  Rewind
How to use Pandas in Python | Python Pandas Tutorial | Python Tutorial | Edureka Rewind
edureka!
14 Parameters in Tableau | Tableau Parameters Examples | Tableau Tutorial  | Edureka Rewind
Parameters in Tableau | Tableau Parameters Examples | Tableau Tutorial | Edureka Rewind
edureka!
15 Top 10 Reasons to Learn Tableau in 2023  | Tableau Certification | Tableau | Edureka Rewind
Top 10 Reasons to Learn Tableau in 2023 | Tableau Certification | Tableau | Edureka Rewind
edureka!
16 Tableau Developer Roles & Responsibilities | Become A Tableau Developer | Tableau | Edureka Rewind
Tableau Developer Roles & Responsibilities | Become A Tableau Developer | Tableau | Edureka Rewind
edureka!
17 Deep Learning With Python | Deep Learning Tutorial For Beginners | Edureka  Rewind
Deep Learning With Python | Deep Learning Tutorial For Beginners | Edureka Rewind
edureka!
18 Realtime Object Detection  | Object Detection with TensorFlow | Edureka | Deep Learning Rewind - 2
Realtime Object Detection | Object Detection with TensorFlow | Edureka | Deep Learning Rewind - 2
edureka!
19 Top 20 Tableau Tips and Tricks in 20 Minutes | Tableau Tutorial | Tableau Training  | Edureka Rewind
Top 20 Tableau Tips and Tricks in 20 Minutes | Tableau Tutorial | Tableau Training | Edureka Rewind
edureka!
20 Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind -  5
Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind - 5
edureka!
21 ReactJS Installation Tutorial | ReactJS Installation On Windows | ReactJS Tutorial | Edureka Rewind
ReactJS Installation Tutorial | ReactJS Installation On Windows | ReactJS Tutorial | Edureka Rewind
edureka!
22 Phases in Cybersecurity  | Cybersecurity Training | Edureka | Cybersecurity Rewind - 2
Phases in Cybersecurity | Cybersecurity Training | Edureka | Cybersecurity Rewind - 2
edureka!
23 What Is React | ReactJS Tutorial for Beginners | ReactJS Training | Edureka Rewind
What Is React | ReactJS Tutorial for Beginners | ReactJS Training | Edureka Rewind
edureka!
24 Cybersecurity Frameworks Tutorial | Cybersecurity Training | Edureka | Cybersecurity Rewind- 2
Cybersecurity Frameworks Tutorial | Cybersecurity Training | Edureka | Cybersecurity Rewind- 2
edureka!
25 React vs Angular 4  | Angular 2 vs React | React & Angular | ReactJS Training | Edureka Rewind - 5
React vs Angular 4 | Angular 2 vs React | React & Angular | ReactJS Training | Edureka Rewind - 5
edureka!
26 ReactJS Components Life-Cycle Tutorial  | React Tutorial for Beginners  | Edureka Rewind
ReactJS Components Life-Cycle Tutorial | React Tutorial for Beginners | Edureka Rewind
edureka!
27 Ethical Hacking using Kali Linux | Ethical Hacking Tutorial | Edureka | Cybersecurity Rewind - 3
Ethical Hacking using Kali Linux | Ethical Hacking Tutorial | Edureka | Cybersecurity Rewind - 3
edureka!
28 Types Of Artificial Intelligence | Artificial Intelligence Explained | What is AI? | Edureka
Types Of Artificial Intelligence | Artificial Intelligence Explained | What is AI? | Edureka
edureka!
29 Top 10 Applications Of Artificial Intelligence in 2023 | Artificial Intelligence| Edureka Rewind
Top 10 Applications Of Artificial Intelligence in 2023 | Artificial Intelligence| Edureka Rewind
edureka!
30 The Future of AI | How will Artificial Intelligence Change the World in 2023? | Edureka Rewind
The Future of AI | How will Artificial Intelligence Change the World in 2023? | Edureka Rewind
edureka!
31 What is Artificial Intelligence | Artificial Intelligence Tutorial For Beginners | Edureka Rewind
What is Artificial Intelligence | Artificial Intelligence Tutorial For Beginners | Edureka Rewind
edureka!
32 Google Cloud IAM | Identity & Access Management on GCP  | Edureka | GCP Rewind - 5
Google Cloud IAM | Identity & Access Management on GCP | Edureka | GCP Rewind - 5
edureka!
33 Google Cloud AI Platform Tutorial | Google Cloud AI Platform   | GCP Training | Edureka Rewind
Google Cloud AI Platform Tutorial | Google Cloud AI Platform | GCP Training | Edureka Rewind
edureka!
34 Projects in Google Cloud Platform  | GCP Project Structure  | GCP Training | Edureka Rewind
Projects in Google Cloud Platform | GCP Project Structure | GCP Training | Edureka Rewind
edureka!
35 How to Become a Data Scientist | Data Scientist Skills | Data Science Training  | Edureka Rewind - 3
How to Become a Data Scientist | Data Scientist Skills | Data Science Training | Edureka Rewind - 3
edureka!
36 Agglomerative and Divisive Hierarchical Clustering Explained | Data Science Training | Edureka Live
Agglomerative and Divisive Hierarchical Clustering Explained | Data Science Training | Edureka Live
edureka!
37 Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind -  5
Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind - 5
edureka!
38 Data Science Project - Covid-19 Data Analysis | Python Training | Edureka | DS Rewind - 6
Data Science Project - Covid-19 Data Analysis | Python Training | Edureka | DS Rewind - 6
edureka!
39 What is Honeycode? | Introduction to Honeycode | Edureka
What is Honeycode? | Introduction to Honeycode | Edureka
edureka!
40 Difference between Amazon AWS and Google Cloud | GCP Training Google Cloud | Edureka Live
Difference between Amazon AWS and Google Cloud | GCP Training Google Cloud | Edureka Live
edureka!
41 DevOps Lifecycle | Introduction To DevOps | DevOps Tools | What is DevOps? | Edureka Rewind
DevOps Lifecycle | Introduction To DevOps | DevOps Tools | What is DevOps? | Edureka Rewind
edureka!
42 Introduction to DevOps | DevOps Tutorial for Beginners | DevOps Tools | DevOps | Edureka Rewind
Introduction to DevOps | DevOps Tutorial for Beginners | DevOps Tools | DevOps | Edureka Rewind
edureka!
43 How to Create Login System using Python | Python Programming Tutorial | Edureka Rewind
How to Create Login System using Python | Python Programming Tutorial | Edureka Rewind
edureka!
44 Python Developer | How to become Python Developer | Python Tutorial  | Edureka Rewind
Python Developer | How to become Python Developer | Python Tutorial | Edureka Rewind
edureka!
45 How to become a Data Engineer | Complete Roadmap to become a Data Engineer| Data Engineer |  Edureka
How to become a Data Engineer | Complete Roadmap to become a Data Engineer| Data Engineer | Edureka
edureka!
46 Azure Data Engineer Certification [DP 203] | How to Become Azure Data Engineer [2023] | Edureka
Azure Data Engineer Certification [DP 203] | How to Become Azure Data Engineer [2023] | Edureka
edureka!
47 Data Analyst vs Data Engineer vs Data Scientist | Data Analytics Masters Program  | Edureka Rewind
Data Analyst vs Data Engineer vs Data Scientist | Data Analytics Masters Program | Edureka Rewind
edureka!
48 DevOps Engineer day-to-day Activities | DevOps Engineer Responsibilities | Edureka Rewind
DevOps Engineer day-to-day Activities | DevOps Engineer Responsibilities | Edureka Rewind
edureka!
49 How to Become a DevOps Engineer?  | DevOps Engineer Roadmap | Edureka | DevOps Rewind
How to Become a DevOps Engineer? | DevOps Engineer Roadmap | Edureka | DevOps Rewind
edureka!
50 How to Become a Data Engineer? | Data Engineering Training | Edureka
How to Become a Data Engineer? | Data Engineering Training | Edureka
edureka!
51 How To Become A Big Data Engineer? | Big Data Engineer Roadmap | Edureka Rewind
How To Become A Big Data Engineer? | Big Data Engineer Roadmap | Edureka Rewind
edureka!
52 Python Integration for Power BI and Predictive Analytics | Power BI Training | Edureka
Python Integration for Power BI and Predictive Analytics | Power BI Training | Edureka
edureka!
53 Power BI KPI Indicators Tutorial | Custom Visuals In Power BI | Power BI Training  | Edureka Rewind
Power BI KPI Indicators Tutorial | Custom Visuals In Power BI | Power BI Training | Edureka Rewind
edureka!
54 Apache HBase Tutorial For Beginners | What is Apache HBase? | Big Data Training | Edureka Rewind
Apache HBase Tutorial For Beginners | What is Apache HBase? | Big Data Training | Edureka Rewind
edureka!
55 Big Data Hadoop Tutorial For Beginners  | Hadoop Training | Big Data Tutorial  | Edureka  Rewind
Big Data Hadoop Tutorial For Beginners | Hadoop Training | Big Data Tutorial | Edureka Rewind
edureka!
56 Big Data Analytics  | Big Data Analytics Use-Cases | Big Data Tutorial | Edureka Rewind
Big Data Analytics | Big Data Analytics Use-Cases | Big Data Tutorial | Edureka Rewind
edureka!
57 What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training  | Edureka  Rewind
What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | Edureka Rewind
edureka!
58 Triggers in Salesforce | Salesforce Apex Triggers | Salesforce  Tutorial  | Edureka Rewind
Triggers in Salesforce | Salesforce Apex Triggers | Salesforce Tutorial | Edureka Rewind
edureka!
59 How To Become A Salesforce Developer | Salesforce For Beginners| Salesforce Training  Edureka Rewind
How To Become A Salesforce Developer | Salesforce For Beginners| Salesforce Training Edureka Rewind
edureka!
60 Java ArrayList Tutorial | Java ArrayList Examples | Java Tutorial | Edureka Rewind
Java ArrayList Tutorial | Java ArrayList Examples | Java Tutorial | Edureka Rewind
edureka!

Related Reads

📰
Causal Inference in Finance: Moving Beyond “What Happened?” to “What Actually Worked?”
Learn to apply causal inference in finance to uncover what actually drives outcomes, beyond just observing patterns
Medium · Data Science
📰
Database Deep Dive Series
Learn database fundamentals and advanced concepts through a series of in-depth articles
Dev.to · Namrata Khorjuwekar
📰
Éclat de l’Avenir Gestion S.A.R.L renforce la clarté des analyses grâce aux rapports intelligents
Éclat de l'Avenir Gestion S.A.R.L improves financial analysis clarity with intelligent reporting, learn how to apply similar techniques to your own data analysis
Dev.to AI
📰
Data Analytics (AI/ML) ROI 101 series: Article 3: Accounting fundamentals for data analytics…
Learn accounting fundamentals to measure data analytics ROI and make informed business decisions
Medium · AI
Up next
Salesforce Tableau CRM & Einstein Discovery Consultant Exam: Full Syllabus Breakdown (New 2025 Bluep
Emily Unfiltered
Watch →