关于触发器
Student
sid name age
SC
sid cn grade
我在把SC.sid设为Student.sid的外键之后,
如何添加一个在删除Student记录之前,要先删除SC中对应记录触发器啊
------解决方案--------------------Create Trigger td_Student on Student
for delete
as
if exists(select 1 from SC where sid in (select sid from deleted))
begin
raiserror( '要先删除SC表中对应的资料! ',16,1)
rollback tran
return
end
go
------解决方案--------------------无需写触发器,你只要设计表外键时选择,级联删除即可.
------解决方案--------------------cascade on delete