创建一触发器Student,当向表中插入或者删除记录时,修改表Class中相应的人数

2024-12-26 14:48:12
推荐回答(2个)
回答1:

create trigger trigger_insert on student
for insert
as
update class
set 人数=人数+1
where unitid=(select unitid from inserted)

create trigger trigger_insert on student
for delete
as
update class
set 人数=人数-1
where unitid=(select unitid from deleted)

回答2:

可能要分成两个触发器,insert,delete触发器