每日博客

时间:上午9:00-12:00

代码:200多行?

博客:1

知识点:数据库

级联删除触发器
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
原文地址:https://www.cnblogs.com/hfy717/p/14583951.html