--创建delete触发器,实现学校信息级联删除
create trigger dSclno_trig on School
instead of delete
as
begin
declare @sclno varchar(20)
select @sclno=Sclno from deleted
delete from Stu_Scl where Sclno=@sclno
delete from Scl_Maj where Sclno=@sclno
delete from School where Sclno=@sclno
end;
--AFTER触发器的应用实现
--创建updata触发器,要求当在学校信息表(School)修改学校编号字段时,Scl_Maj中的学校编号也相应修改
create trigger Sclno_trig
on School
for update
as
if update(Sclno)
update Scl_Maj
set Scl_Maj.Sclno=(select Sclno from inserted)
where Scl_Maj.Sclno=(select Sclno from deleted)