我有下表设置。
Bag
|
+-> BagID (Guid)
+-> BagNumber (Int)
BagCommentRelation
|
+-> BagID (Int)
+-> CommentID (Guid)
BagComment
|
+-> CommentID (Guid)
+-> Text (varchar(200))
BagCommentRelation 具有 Bag 和 BagComment 的外键。
所以,我为这两个外键打开了级联删除,但是当我删除一个包时,它不会删除评论行。
是否需要为此触发触发器?还是我错过了什么?
(我使用的是 SQL Server 2008)
注意:发布请求的 SQL。这是 BagCommentRelation 表的定义。(我的 bagID 类型错误(我认为它是一个 guid,但它是一个 int)。)
CREATE TABLE [dbo].[Bag_CommentRelation](
[Id] [int] IDENTITY(1,1) NOT NULL,
[BagId] [int] NOT NULL,
[Sequence] [int] NOT NULL,
[CommentId] [int] NOT NULL,
CONSTRAINT [PK_Bag_CommentRelation] PRIMARY KEY CLUSTERED
(
[BagId] ASC,
[Sequence] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Bag_CommentRelation] WITH CHECK ADD CONSTRAINT [FK_Bag_CommentRelation_Bag] FOREIGN KEY([BagId])
REFERENCES [dbo].[Bag] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Bag_CommentRelation] CHECK CONSTRAINT [FK_Bag_CommentRelation_Bag]
GO
ALTER TABLE [dbo].[Bag_CommentRelation] WITH CHECK ADD CONSTRAINT [FK_Bag_CommentRelation_Comment] FOREIGN KEY([CommentId])
REFERENCES [dbo].[Comment] ([CommentId])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Bag_CommentRelation] CHECK CONSTRAINT [FK_Bag_CommentRelation_Comment]
GO
此表中的行会删除,但注释表中的行不会。