当前位置:网站首页>Whether MySQL has triggers

Whether MySQL has triggers

2022-06-21 20:07:00 Yisu cloud

mysql Is there a trigger

This article mainly introduces “mysql Is there a trigger ” Knowledge about , Xiaobian shows you the operation process through practical cases , The operation method is simple and fast , Practical , Hope this article “mysql Is there a trigger ” The article can help you solve problems .

mysql There are triggers .MySQL Triggers are a set of SQL Statement set , yes MySQL A powerful tool for managing data in , It is mainly used to protect the data in the table .MySQL Three triggers are supported :1、INSERT trigger , Is in INSERT Triggers that respond before or after statement execution ;2、UPDATE trigger , Is in UPDATE Triggers that respond before or after statement execution ;3、DELETE trigger , Is in DELETE Triggers that respond before or after statement execution .

The operating environment of this tutorial :windows7 System 、mysql8 edition 、Dell G3 The computer .

mysql There are triggers .

MySQL The trigger is the same as the stored procedure , Are embedded in MySQL One of the procedures in , Is a set of... Stored in the database directory SQL Statement set , yes MySQL A powerful tool for managing data in . The difference is that executing stored procedures uses CALL Statement to call , And trigger execution doesn't need to use CALL Statement to call , It doesn't need to be started by hand , It is triggered by related operations on the data table 、 Activate to execute . For example, when it comes to student Table operation (INSERT,DELETE or UPDATE) It will be activated to execute .

Triggers are closely related to data tables , It is mainly used to protect the data in the table . Especially when there are multiple tables that are related to each other , Triggers enable different tables to maintain data consistency .

stay MySQL in , Only execute INSERT、UPDATE and DELETE The trigger can only be activated during operation , Other SQL Statement does not activate the trigger .

Advantages and disadvantages of flip flops

The advantages of triggers are as follows :

  • Trigger execution is automatic , Execute immediately after making corresponding modifications to the data of the trigger related table .

  • Triggers can be implemented better than FOREIGN KEY constraint 、CHECK Constrain more complex checks and actions .

  • Triggers enable cascading changes to table data , To a certain extent, it ensures the integrity of the data .

The disadvantages of triggers are as follows :

  • Business logic implemented with triggers is difficult to locate when problems arise , Especially when multiple triggers are involved , It will make later maintenance difficult .

  • Extensive use of triggers can easily cause code structure to be disrupted , Increases the complexity of the program ,

  • If the amount of data to be changed is large , The execution efficiency of triggers will be very low .

MySQL There are three kinds of triggers :

MySQL There are three types of triggers supported :INSERT trigger 、UPDATE Trigger and DELETE trigger .

1) INSERT trigger

   stay INSERT Triggers that respond before or after statement execution .

2) UPDATE trigger

   stay UPDATE Triggers that respond before or after statement execution .

3) DELETE trigger

   stay DELETE Triggers that respond before or after statement execution .

About “mysql Is there a trigger ” That's all for , Thanks for reading . If you want to know more about the industry , You can pay attention to the Yisu cloud industry information channel , Xiaobian will update different knowledge points for you every day .

原网站

版权声明
本文为[Yisu cloud]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211827198495.html