EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials MySQL Tutorial MySQL DROP TRIGGER
Secondary Sidebar
MySQL Tutorial
  • Functions
    • MySQL Function
    • MySQL Aggregate Function
    • MySQL String functions
    • MySQL Date Functions
    • MySQL Window Functions
    • MySQL Math Functions
    • MySQL Boolean
    • Cursor in MySQL
    • Condition in MySQL
    • MySQL BETWEEN
    • Insert in MySQL
    • MySQL IFNULL()
    • MySQL TIMESTAMPDIFF()
    • MySQL COALESCE()
    • MySQL count()
    • MIN() in MySQL
    • MySQL Numeric
    • MySQL field()
    • MySQL FIND_IN_SET()
    • MySQL avg()
    • MySQL MAX() Function
    • MySQL BIN()
    • MySQL Concat
    • MySQL DECODE()
    • MySQL REGEXP_REPLACE()
    • MySQL Asynchronous
    • MySQL innodb_buffer_pool_size
    • MySQL key_buffer_size
    • MySQL TRUNCATE()
    • MySQL ROW_NUMBER()
    • NOT in MySQL
    • MySQL IN Operator
    • LIKE in MySQL
    • ANY in MySQL
    • MySQL NOT IN
    • MySQL CHECK Constraint
    • MySQL DISTINCT
    • MySQL ALL
    • MySQL Union
    • MySQL UNION ALL
    • MySQL EXISTS
    • MySQL ON DELETE CASCADE
    • MySQL REGEXP
    • MySQL Index
    • MySQL Add Index
    • MySQL REINDEX
    • MySQL UNIQUE INDEX
    • MySQL Clustered Index
    • MySQL? InnoDB Cluster
    • Table in MySQL
    • ALTER TABLE MySQL
    • MySQL Temporary Table
    • MySQL Clone Table
    • MySQL Repair Table
    • MySQL Lock Table
    • MySQL Optimize Table
    • TRUNCATE TABLE MySQL
    • MySQL Table Dump
    • MySQL Update Set
    • MySQL ALTER TABLE Add Column
    • MySQL RANK()
    • MySQL CTE
    • MySQL LAG()
    • MySQL GROUP_CONCAT()
    • MySQL EXTRACT()
    • MySQL REPLACE
    • MySQL AUTO_INCREMENT
    • MySQL SYSDATE()
    • MySQL NULLIF()
    • MySQL Substring
    • MySQL SUBSTRING_INDEX()
    • MySQL LOWERCASE
    • MySQL Row
    • MySQL NOW
    • MySQL CEIL
    • MySQL Alias
    • MySQL Trigger
    • MySQL SHOW Triggers
    • MySQL UPDATE Trigger
    • MySQL DELETE Trigger
    • MySQL AFTER UPDATE Trigger
    • MySQL Stored Procedure
    • ROLLUP in MySQL
    • MySQL? INSTR()
    • MySQL Subquery
    • MySQL Timestamp
    • MySQL? Hour()
    • MySQL MOD()
    • MySQL DATE_FORMAT()
    • ALTER Column in MySQL
    • MySQL Rename Column
    • MySQL Interval
    • MySQL CURDATE
    • MySQL BIT
    • MySQL Binlog
    • MySQL Average
    • MySQL TEXT
    • MySQL SHOW
    • MySQL Offset
    • MySQL Timezone
    • mysql_real_escape_string
    • MySQL Datetime
    • MySQL DATE_SUB()
    • MySQL FULLTEXT
    • MySQL DATE_ADD()
    • MySQL sum()
    • MySQL Merge
    • MySQL BigInt
    • MySQL ROUND
    • MySQL VARCHAR
    • MySQL Decimal
    • MySQL Limit
    • MySQL today()
    • MySQL WEEKDAY
    • MySQL Split
    • MySQL Create Function
    • MySQL BLOB
    • MySQL encode()
    • MySQL Primary Key
    • MySQL Foreign Key
    • Unique Key in MySQL
    • MySQL Drop Foreign Key
    • MySQL DROP TRIGGER
    • MYSQL Database
    • Delete Database MySQL
    • MySQL Root
    • MySQL Root Password
    • MySQL Client
    • MySQL Users
    • MySQL?User Permissions
    • MySQL add user
    • MySQL List User
    • MySQL Show Users
    • MySQL User Password
    • MySQL?Cardinality
    • MySQL Workbench
    • MySQL Backup
    • MySQL REVOKE
    • MySQL Dump
    • MySQL Cluster
    • MySQL Partitioning
    • MySQL Full Text Search
    • MySQL Admin Tool
    • MySQL Export Database
    • MySQL Export to CSV
  • Basic
    • MySQL floor
    • MySQL DESCRIBE table
    • MySQL encryption
    • Introduction to MySQL
    • Is SQL Server a Database?
    • What is MySQL
    • Is MySQL Programming Language
    • MySQL Server
    • MySQL AB
    • MySQL Community Server
    • How To Install MySQL
    • MySQL Versions
    • MySQL OpenSource
    • MySQL GUI Tools
    • MySQL Grant
    • MySQL Error 1064
    • MySQL Drop Database
    • MySQL not equal
    • MySQL SELECT INTO Variable
    • MySQL Commands
    • MySQL Operators
    • What is MySQL Schema
    • Wildcards in MySQL
    • MySQL Constraints
    • MySQL Administration
    • MySQL Data Type
    • MYSQL COMMIT
    • MySQL FORMAT
    • Timestamp to Date in MySQL
    • MySQL DATEDIFF
    • MySQL?Incremental Backup
    • MySQL JSON Data Type
    • MySQL ENUM
    • MySQL Default Port
    • Cheat Sheet MySQL
  • Queries
    • MySQL Queries
    • MySQL Query Commands
    • SELECT in MySQL
    • MySQL INSERT IGNORE
    • MySQL having
    • ORDER BY in MySQL
    • MySQL Cheat Sheet
    • MySQL ORDER BY Random
    • MySQL ORDER BY DESC
    • MySQL GROUP BY
    • MySQL GROUP BY Count
    • MySQL GROUP BY month
    • MySQL WHERE Clause
    • MySQL WITH
    • MySQL FETCH
    • MySQL DDL
    • MySQL DML
    • MySQL WHERE IN Array
    • MySQL Fetch Array
    • MySQL ISNULL
    • MySQL Index Types
    • Mysql? Export Schema
    • Amazon RDS for MySQL
    • MySQL greatest
  • Database
    • What is Data Modeling
    • What is Data Processing
    • DBMS Architecture
    • DBMS Keys
    • Careers in Database Administration
    • What is MySQL Database
    • MySQL Relational Database
    • How to Connect Database to MySQL
    • MySQL Database Repair
    • RDBMS Interview Questions
    • DBMS Interview Questions
  • Joins
    • Joins in MySQL
    • MySQL Outer Join
    • Left Outer Join in MySQL
    • MySQL Self Join
    • Natural Join in MySQL
    • MySQL DELETE JOIN
    • MySQL Update Join
    • MySQL Cross Join
  • Advanced
    • MySQL Formatter
    • MySQL TINYINT
    • MySQL Grant All Privileges
    • MySQL DROP TABLE
    • MySQL rename database
    • MySQL Flush Privileges
    • MySQL super Privilege
    • MySQL Character Set
    • MySQL Log File
    • MySQL Flush Log
    • Grant Privileges MySQL
    • MySQL WHILE LOOP
    • IF Statement in MySQL
    • MySQL CASE Statement
    • MySQL IF Function
    • MySQL IF EXISTS
    • MySQL UUID
    • Views in MySQL
    • MySQL Replication
    • MySQL Partition
    • Toad for MySQL
    • Navicat for MySQL
    • MySQL AES_Encrypt
    • MySQL Performance Tuning
    • MySQL Transaction
    • MySQL? sort_buffer_size
    • MySQL? Sync
    • MySQL? Query Cache
    • MySQL Collation
    • MySQL ODBC Driver
    • MySQL Partitioning
    • MySQL InnoDB
    • MySQL Float vs Decimal
    • MySQL Union vs Union All
  • Interview Questions
    • MySQL Interview Questions

Related Courses

MS SQL Certification Courses

Oracle Certification Courses

PL/SQL Certification Courses

MySQL DROP TRIGGER

MySQL DROP TRIGGER

Definition of MySQL Drop Trigger

MySQL DROP Trigger is a MySQL statement command that is responsible to delete an existing trigger from the database. Like other MySQL Triggers, this DROP trigger is also defined as a stored code program that is invoked when required for a table associated with it. Before we execute the MYSQL DROP trigger the user should gain the administrative privilege to apply the changes for the database table to generate the desired results. We should keep in mind that when any table is dropped from the MySQL database then automatically all the triggers created and linked with the table will be deleted as well.

Syntax:

The MySQL DROP Trigger has the following basic syntax to delete a stored trigger program associated to that specific database table:

DROP TRIGGER [IF EXISTS] [SchemaName.] TriggerName;

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

From the above structure we come to know that:

  • Initially, you need to provide a particular name to the trigger which is required to be removed or dropped after the keywords DROP TRIGGER.
  • In the next step, you will have to give the name of the schema where the trigger is stored or created previously. In case if the SchemaName is missing or not mentioned then, the query statement will delete the trigger present in the current MySQL database.
  • IF EXISTS is added to the syntax to provide an option provisionally to check if the trigger that we need to drop is available on that particular schema/table or not.

How DROP TRIGGER Statement Work in MySQL?

  • There can be various triggers implemented in MySQL Database tables. You need to work for those tables only where the trigger that you want to be dropped is associated with it.
  • The trigger was created earlier and for some reason or to avoid the event occurring we can remove the trigger. This action of using DROP Trigger will also not display the logs stored in the trigger-related table. So, we need to be confirmed and sure if we want to delete the trigger or not.
  • As per the above syntax, we need schema name and trigger name to be mentioned with the DROP Trigger statement. At the same time, we must include the IF EXISTS option also.
  • Suppose if you try to delete a trigger that is not present in the table without applying the option IF EXISTS then, the MySQL server will produce an error. Another is the option IF EXISTS is added to the query then, the server will generate just a NOTE rather than that you can further see through SHOW WARNINGS query command.
  • You need to require the administrative level of access to perform the DROP TRIGGER statement for the linked table. Also, dropping the table will result in the removal of all triggers within it.

Examples of MySQL DROP TRIGGER

Let us examine through the following examples to demonstrate more about DROP Trigger and its working & uses in MySQL:

In the beginning, we will first create a table in the database for executing the queries. Let it be named as Rooms where the records are stored and for which a trigger will be created.

The SQL query for creating a table is as follows:

DROP TABLE IF EXISTS Rooms;

CREATE TABLE Rooms ( Room_ID INT PRIMARY KEY AUTO_INCREMENT, RoomName VARCHAR(255) NOT NULL, Flat_Num INT NOT NULL);

Also, let us enter a few records using the INSERT query as:

INSERT INTO Rooms(Room_ID, RoomName, Flat_Num) VALUES('1','pawan Vihar','10');

Querying data rows from Rooms table to see its insides:

SELECT * FROM Rooms;

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,408 ratings)

Output:

MySQL DROP TRIGGER-1.1

Again, forming subsequent table to save the variations that happened on the parental table Rooms after any update command if we are using an AFTER UPDATE Trigger as follows:

CREATE TABLE Roomlogs ( User_ID VARCHAR(255), Info_Update VARCHAR(255));

View the table at present:

SELECT * FROM Roomlogs;

Output:

MySQL DROP TRIGGER-1.2

Now, we are moving towards making the statement to implement an AFTER UPDATE trigger on the Rooms table:

DELIMITER $$
CREATE TRIGGER room_updates
AFTER UPDATE ON Rooms FOR EACH ROW
BEGIN
INSERT into Roomlogs(User_ID,Info_Update) VALUES (user(), CONCAT('Updated Room Info (',OLD.Room_ID,' ',OLD.RoomName,' ',OLD.Flat_Num,') to (',NEW.Room_ID,' ',NEW.RoomName,' ',NEW.Flat_Num,')'));
END$$
DELIMITER ;

After room_updates trigger is generated, this will be frequently triggered before stirring of an update event for every row in the rooms table.

To observe in detail, when you update any value in the Flat_Num column then, a fresh row will be inserted to the roomlogs table to record the changes made.

UPDATE Rooms SET Flat_Num = Flat_Num + 5 WHERE Room_ID <10;

Output:

MySQL DROP TRIGGER-1.3

Again, view to your Roomlogs table and understand the transformation and effect of AFTER UPDATE trigger using the following query:

SELECT * FROM Roomlogs;

Output:

MySQL DROP TRIGGER-1.4

As you can see in the screenshot above that after creating the AFTER UPDATE triggerand making certain modifications in the table rows using UPDATE query, the Roomlogs table has recorded the user id and information about the changes made in the trigger related table Rooms. Suppose, we will create another trigger in the Payment table as follows:

Payment table

MySQL DROP TRIGGER-1.5

Payment_logs table to record the logs after an update query:

Output-1.6

Trigger Code:

DELIMITER $$
CREATE TRIGGER `payment_update`
AFTER UPDATE ON `payment`  FOR EACH ROW
BEGIN
IF OLD.PAmount <> new.PAmount THEN
INSERT INTO Payment_logs (User_ID,Before_PAmount, After_PAmount)
VALUES (user(), old.PAmount, new.PAmount);
END IF;
END$$
DELIMITER ;

You can even view the trigger present in the Rooms table by going to the Triggers option in the phpMyAdmin server as follows:

SHOW TRIGGERS;

Output:

Output-1.7

Finally, we will proceed towards the use of DROP Trigger in MySQL to show the result on table Rooms. Let us delete the second trigger named room_updates using the SQL command below:

DROP TRIGGER room_updates;

Again, view the triggers on table Rooms lastly to validate the removal of the above mentioned trigger.

SHOW TRIGGERS;

Output:

Output-1.8

See the trigger has been deleted with its log info from the Rooms table.

Conclusion

  • Normally, we create MySQL trigger to produce information to the user for any changes made in the database like MySQL operations: INSERT, DELETE, UPDATE, ALTER statement queries and keep a log of those modifications.
  • When we need to remove any trigger available to a specific table then, we will use MySQL DROP Trigger command statement in that database table.

Recommended Articles

This is a guide to MySQL DROP TRIGGER. Here we also discuss the definition and how drop trigger statement work in MySQL? along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. MySQL IF Function
  2. MySQL UUID
  3. MySQL sum()
  4. MySQL Partition
Popular Course in this category
MySQL Training Program (12 Courses, 10 Projects)
  12 Online Courses |  10 Hands-on Projects |  92+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

MS SQL Training (16 Courses, 11+ Projects)4.9
Oracle Training (14 Courses, 8+ Projects)4.8
PL SQL Training (4 Courses, 2+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more