用update前的列就用old,要引用update后的列就用new
old为正在删除信息 new 正在插入的信息
//删除tab1表记录后自动将tab2表中对应的记录删去
DROP TRIGGER IF EXISTS t_afterdelete_on_tab1;
CREATE TRIGGER t_afterdelete_on_tab1
AFTER DELETE ON tab1
FOREACH ROW
BEGIN
delete from tab2 where tab2_id=old.tab1_id;
END;
DELETEF ROM tab1 WHERE tab1_id='0001';
delimiter $
create trigger t_good
after INSERT
on good_order
for each row
BEGIN
UPDATE good_store set gnum=gnum-new.onum where id = new.oid;
end;
$$
delimiter;
insert into good_order values(null,1,10);
use hh;
DROP TRIGGER if EXISTS t_del;
delimiter $$
create trigger t_del
BEFORE DELETE
on student
for each row
BEGIN
DELETE from sc where scsno = old.sno;
END;
$$
delimiter;
DELETE from student where sno ='200215122';