每日博客
数据库
级联删除触发器
CREATE TRIGGER tr2 ON Student AFTER DELETE As BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON ; -- Insert statements for trigger here delete from sc where sno = (select sno from deleted) END GO
级联修改触发器
ALTER TRIGGER[dbo] . [tr3] ON[dbo] . [Student] AFTER UPDATE AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for trigger here update SC set sno= ( select sno from inserted) where sno=(select sno from deleted ) END
受限插入触发器
CREATE TRIGGER tr4 ON student AFTER INSERT As BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for trigger here delete from sc where sno=( select sno from inserted where sno not in (select sno from student ) ) or cno=(select cno from inserted where cno not in (select cno from course ) ) END Go