mysql:triggers
參考
http://www.mysqltutorial.org/mysql-triggers.aspx
mysql:triggers
被預先編寫并存儲在表中的程序, 該程序被特定的 events觸發, 比如 對表的 DML 操作
By definition, a trigger or database trigger is a stored program executed automatically to respond to a specific event e.g., insert, update or delete occurred in a table.
被用于: 保護數據的完整性和一致性,
以及 自動 logging 和 審計 等
A SQL trigger is a set of SQL statements stored in the database catalog. A SQL trigger is executed or fired whenever an event associated with a table occurs e.g., insert, update or delete.
trigger vs stored procedure
A SQL trigger is a special type of stored procedure. It is special because it is not called directly like a stored procedure. The main difference between a trigger and a stored procedure is that a trigger is called automatically when a data modification event is made against a table whereas a stored procedure must be called explicitly.
advantages of Using triggers
提供了一個檢查 數據完整性和一致性的方式
可以在數據庫內捕捉 業務邏輯的錯誤
支持 run scheduled task
4, 支持對 數據變更的審查
disadvantages of Using triggers
triggers僅能提供一種對數據審查的擴展, 而不能替代所有的審查工作
triggers 執行對 clients不可見
triggers 加大了mysql server 的負擔
triggers 實現:
You must use a unique name for each trigger associated with a table
The tablename.TRG file maps the trigger to the corresponding table.
the triggername.TRN file contains the trigger definition.
MySQL triggers cannot:
- Use SHOW, LOAD DATA, LOAD TABLE, BACKUP DATABASE, RESTORE, FLUSH and RETURNstatements.
- Use statements that commit or rollback implicitly or explicitly such as COMMIT , ROLLBACK , START TRANSACTION , LOCK/UNLOCK TABLES , ALTER , CREATE , DROP , RENAME.
- Use prepared statements such as PREPAREand EXECUTE.
- Use dynamic SQL statements.
create triggers
定義 tables 用來存放 triggers 獲取的數據;
定義 tiggers, associated with a table;
scheduled event
類似于 定時器
總結
以上是生活随笔為你收集整理的mysql:triggers的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 后门触发器之频域角度——Rethinki
- 下一篇: Jenkins高级篇之Pipeline语