首页 新闻 会员 周边 捐助

触发器中关于集联删的问题,Help Me!

0
悬赏园豆:20 [已解决问题] 解决于 2008-03-24 11:14
<P>说明:studnet 表中外键CourseID为Course表中的主键,当删除Course表中的CourseID时,对应Studnet表中的也被删除。 <BR>下面这个有错误,我觉的是违反了主外键的一些规则,该怎么写啊? <BR>Create Trigger Delete_ID <BR>On Course <BR>for delete <BR>as&nbsp; </P> <P>DECLARE @CourseID int <BR><BR>select @CourseID = CourseID FROM Course deleted <BR><BR>IF EXISTS (Select * from Student where CourseID = @CourseID) <BR>begin<BR>delete From Student where Student.CourseID=deleted.CourseID <BR>end</P> <P></CD></P>
HamunNet的主页 HamunNet | 初学一级 | 园豆:25
提问于:2008-03-07 13:45
< >
分享
最佳答案
1
Create Trigger Delete_ID On Course before delete as delete From Student where Student.CourseID in (select id from deleted)
重典 | 老鸟四级 |园豆:2442 | 2008-03-22 23:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册