有三个表category news comment  category中的id对应new中的caId news中的id 对应comment中的newsId
下面是触发器的内容我看不懂那位帮解释下 越清楚越好:
--赵科制作
--2011 -2- 25
--删除类别触发器
CREATE TRIGGER [trigCategoryDelete] ON [dbo].[category] 
instead of  DELETE 
AS
BEGIN
declare @caId  int
select @caId=id from deleteddelete comment where newsId in (select newsId from news where caId=@caId)delete news where caId=@caIddelete category where id=@caId
END

解决方案 »

  1.   


                //在category表上建立名字为trigCategoryDelete的触发器
                CREATE TRIGGER [trigCategoryDelete] ON [dbo].[category]  
                //指定执行触发器而不是执行触发 SQL 语句,从而替代触发语句的操作。这个一句话说不清,请参考:http://wenku.baidu.com/view/d1cab7e9856a561252d36fe8.html
                instead of DELETE 
                //触发器要执行的工作:
                AS
                BEGIN
                //声明int类型参数caID
                declare @caId int
                //
                select @caId=id from deleted
                //删除caID为参数@caID的新闻下的评论
                delete comment where newsId in (select newsId from news where caId=@caId)
                //删除caID为@caID的新闻
                delete news where caId=@caId
                //删除id为@caID的类别
                delete category where id=@caId
                END
      

  2.   

    以上触发器的含义是:
    如果你在category表执行了删除操作,触发器被触发,触发器执行定义的操作~~~~~~~~~~~~没啥解释的,说起来真绕口~~
      

  3.   

    一看这个代码,就知道无法应付delete语句影响2条以上记录时的情况。这类代码在我的团队中是bug的。
      

  4.   

     delete comment where newsId in (select newsId from news where caId=@caId)