首页 新闻 赞助 找找看

触发器和外键约束问题

0
悬赏园豆:40 [已关闭问题] 关闭于 2011-05-20 16:09

1 用触发器实现级联删除
2
问题:创建外键约束,触发器就没用,怎么改触发器
3 帮帮忙
4 表1:
5 --创建帖子表
6 create table Invitation
7 (
8 ID int identity(1,1) not null primary key,
9 CategoryName varchar(50) not null,
10 InvitationTitle varchar(50) not null,
11 InvitationContent text not null
12 )
13
14 表2:
15 --创建评论表
16 create table Comment
17 (
18 ID int identity(1,1) not null primary key,
19 InvitationID int not null,
20 CommentContent text not null
21 )
22
23
24 --创建外键
25 alter table Comment
26 add constraint FK_Comment_Invitation
27 foreign key(InvitationID)references Invitation(ID)
28
29 --触发器
30 --1.删除帖子时候连同其下的评论一起删除
31 create trigger DeleteInvtation on Invitation for delete
32 as
33 declare @ID varchar(50)
34 select @ID=ID from Deleted
35 delete from Comment where InvitationID=@ID

问题补充:

无人。。。问题解决的把for改为instead of

天爀的主页 天爀 | 初学一级 | 园豆:160
提问于:2011-05-20 15:40
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册