
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Drop trigger if exists in MySQL?
To drop trigger, use DROP command. The syntax is as follows −
DROP TRIGGER IF EXISTS yourTriggerName;
To understand the above syntax, you need to have a trigger in your current database.
To check the trigger is present or not, you can use below query. We have a trigger in our database −
mysql> show triggers;
The following is the output −
+-------------+--------+---------------+------------------------------------------------------------------------+--------+------------------------+--------------------------------------------+---------+----------------------+----------------------+--------------------+ | Trigger | Event | Table | Statement | Timing |Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation | +-------------+--------+---------------+------------------------------------------------------------------------+--------+------------------------+--------------------------------------------+---------+----------------------+----------------------+--------------------+ | CheckSalary | INSERT | employeetable | if new.EmployeeSalary < 1000 then setnew.EmployeeSalary = 10000;end if | BEFORE | 2018-12-31 17:33:29.54 |STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | root@% | utf8 |utf8_general_ci | utf8mb4_0900_ai_ci | +-------------+--------+---------------+------------------------------------------------------------------------+--------+------------------------+--------------------------------------------+---------+----------------------+----------------------+--------------------+ 1 row in set (0.17 sec)
Here, we have trigger with the name ‘CheckSalary’ on employeetable. Drop the trigger ‘CheckSalary’ using DROP command. The query is as follows −
mysql> drop trigger if exists CheckSalary; Query OK, 0 rows affected (0.30 sec)
Use the show triggers command to check whether the trigger is present or not. The query is as follows −
mysql> show triggers; Empty set (0.00 sec)
Look at the above result now, the trigger is not present the database ‘test’. We removed it using drop.
- Related Articles
- Check if a user exists in MySQL and drop it?
- MySQL appears to DROP USER but user still exists in MySQL.users table?
- Check if table exists in MySQL and display the warning if it exists?
- What happens with the trigger when we will drop the table having that trigger?
- How to check if a MySQL database exists?
- Check if value exists in a comma separated list in MySQL?
- Check if a value exists in a column in a MySQL table?
- How to check if value exists with MySQL SELECT 1?
- Best way to test if a row exists in a MySQL table
- Check if a table is empty or not in MySQL using EXISTS
- What does DELIMITER // do in a Trigger in MySQL?
- How to ceate MySQL Trigger before Insert?
- Check if MySQL entry exists and if it does, how to overwrite other columns?
- Check if Table, View, Trigger, etc present in Oracle
- How to check if a table exists in MySQL and create if it does not already exist?

Advertisements