mysql:triggers
參考
http://www.mysqltutorial.org/mysql-triggers.aspx
mysql:triggers
被預(yù)先編寫并存儲在表中的程序, 該程序被特定的 events觸發(fā), 比如 對表的 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.
被用于: 保護(hù)數(shù)據(jù)的完整性和一致性,
以及 自動(dòng) logging 和 審計(jì) 等
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
提供了一個(gè)檢查 數(shù)據(jù)完整性和一致性的方式
可以在數(shù)據(jù)庫內(nèi)捕捉 業(yè)務(wù)邏輯的錯(cuò)誤
支持 run scheduled task
4, 支持對 數(shù)據(jù)變更的審查
disadvantages of Using triggers
triggers僅能提供一種對數(shù)據(jù)審查的擴(kuò)展, 而不能替代所有的審查工作
triggers 執(zhí)行對 clients不可見
triggers 加大了mysql server 的負(fù)擔(dān)
triggers 實(shí)現(xiàn):
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 獲取的數(shù)據(jù);
定義 tiggers, associated with a table;
scheduled event
類似于 定時(shí)器
總結(jié)
以上是生活随笔為你收集整理的mysql:triggers的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 后门触发器之频域角度——Rethinki
- 下一篇: oracle数据库有触发器,Oracle