Home > Database > Mysql Tutorial > How to cancel mysql trigger

How to cancel mysql trigger

青灯夜游
Release: 2022-06-27 17:13:06
Original
3003 people have browsed it

In mysql, you can use the DROP TRIGGER statement to cancel a defined trigger. The syntax is "DROP TRIGGER table name. Trigger name;" or "DROP TRIGGER trigger name; ", the name of the trigger. It must have a unique name in the current database; if the "table name" option is not omitted, it means canceling the trigger associated with the specified table.

How to cancel mysql trigger

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

MySQL triggers, like stored procedures, are programs embedded in MySQL and are powerful tools for data management in MySQL. The difference is that the execution of a stored procedure requires a CALL statement, while the execution of a trigger does not require a CALL statement or manual startup. Instead, it is triggered and activated through related operations on the data table to achieve execution. For example, its execution will be activated when an operation (INSERT, DELETE or UPDATE) is performed on the student table.

Triggers are closely related to data tables and are mainly used to protect the data in the tables. Especially when there are multiple tables that are related to each other, triggers can maintain data consistency in different tables.

In MySQL, triggers can only be activated when performing INSERT, UPDATE, and DELETE operations. Other SQL statements will not activate triggers.

So how to cancel (delete) the defined trigger?

In MySQL, you can use the DROP TRIGGER statement to delete triggers that have been defined in MySQL.

DROP TRIGGER 触发器名; 
//或
DROP TRIGGER 表名.触发器名;
Copy after login

For example, if you want to delete the before_employees_update trigger associated with the employees table, you can execute the following statement:

DROP TRIGGER employees.before_employees_update;
Copy after login

[Example] Delete the double_salary trigger

DROP TRIGGER double_salary;
Copy after login

How to cancel mysql trigger

After deleting the double_salary trigger, when inserting records into data table tb_emp6 again, the data in data table tb_emp7 no longer changes

INSERT INTO tb_emp6
VALUES (3,'C',1,200);
Copy after login

How to cancel mysql trigger

SELECT * FROM tb_emp6;
Copy after login

How to cancel mysql trigger

SELECT * FROM tb_emp7;
Copy after login

How to cancel mysql trigger

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to cancel mysql trigger. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template