复习下sql server 的触发器
创建触发器前要写上是否存在某个触发器,如果存在,则删掉它
--创建insert插入类型触发器
if (object_id('tgr_classes_insert', 'tr') is not null) //红色部分自己不太熟悉,括号也要记得加上
drop trigger tgr_classes_insert
执行或修改触发器的语法是alert(大小写都可以哦!)
--以下是自己创建的,该触发器可以删除主键表和外键表相关联的数据
if (object_id('deleteTopic', 'tr') is not null) //红色部分自己不太熟悉,括号也要记得加上
drop trigger tgr_classes_insert
CREATE TRIGGER [deleteTopic]
ON [dbo].[bbsTopic]
AFTER delete
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @topicId int
delete bbsTopic where topicId=@topicId
delete bbsTopicCollect where topicId=@topicId
END
本人博客的文章若有侵犯他人的地方,请告知!若有写的不对的地方,请指正!谢谢!