c mysql触发器,mysql触发器使用笔记
mysql觸發(fā)器使用筆記CREATE TRIGGER trigger_name
trigger_time
trigger_event ON tbl_name
FOR EACH ROW
trigger_stmt
trigger_name:標(biāo)識(shí)觸發(fā)器名稱,用戶自行指定;
trigger_time:標(biāo)識(shí)觸發(fā)時(shí)機(jī),取值為 BEFORE 或 AFTER;
trigger_event:標(biāo)識(shí)觸發(fā)事件,取值為 INSERT、UPDATE 或 DELETE;
tbl_name:標(biāo)識(shí)建立觸發(fā)器的表名,即在哪張表上建立觸發(fā)器;
trigger_stmt:觸發(fā)器程序體,可以是一句SQL語(yǔ)句,或者用 BEGIN 和 END 包含的多條語(yǔ)句。
實(shí)例
DELIMITER $
create trigger tri_stuInsert after insert
on student for each row
begin
declare c int;
set c = (select stuCount from class where classID=new.classID);
update class set stuCount = c + 1 where classID = new.classID;
end$
DELIMITER
總結(jié)
以上是生活随笔為你收集整理的c mysql触发器,mysql触发器使用笔记的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: vlookup练习_VLOOKUP拉住她
- 下一篇: 深度学习入门之感知器(原理+代码)