自從給了QA數據庫權限,發生數據被刪除的致使異常的狀況。因此設置了trigger防止數據的誤刪。sql
在SQLyog中選中須要保護的數據表,右擊,選擇「Create Trigger...」數據庫
調整生成的SQL,如:code
DELIMITER $$ CREATE /*[DEFINER = { user | CURRENT_USER }]*/ TRIGGER `demo`.`cant delete` BEFORE DELETE ON `demo`.`pricetag` FOR EACH ROW BEGIN declare msg varchar(255); set msg="can not delete price tag"; SIGNAL SQLSTATE 'HY000' SET MESSAGE_TEXT = msg; END$$ DELIMITER ;
執行該SQL語句,再次刪除數據就會報錯了:blog
要查看trigger,能夠經過class
show triggers;
要刪除trigger,能夠經過權限
drop trigger `trigger_name`;