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