SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: HF_Ultrastrong -- Create date: 2015年7月5日14:39:00 -- Description: 删除类别(连同其下的新闻及新闻评论一起删除) -- ============================================= CREATE PROCEDURE DeleteCategoryAndNewsAndComment @Caid int AS BEGIN begin transaction --定义局部变量 declare @errorSum int --初始化临时变量 set @errorSum=0 --执行SQL语句(根据分类,查询出此分类下创建的所有新闻,然后根据新闻编号删除其下的所有评论) delete from Tb_Comment where NewsId in (select ID from Tb_News where CaId = @Caid) --累计是否有错误 set @[email protected][email protected]@error --执行SQL语句 delete from Tb_News where CaId = @Caid --累计是否有错误 set @[email protected][email protected]@error --执行SQL语句 delete from Tb_Category where ID = @Caid --Tb_Category--Tb_Categorsy调试 --累计是否有错误 set @[email protected][email protected]@error --如果有错误 if @errorSum<>0 --执行回滚 begin rollback transaction end --否则提交事物 else begin commit transaction end END GO
时间: 2024-11-09 06:12:53