首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

关于触发器递归死循环的有关问题

2012-01-12 
关于触发器递归死循环的问题CREATE TRIGGER delfiledon tablename1 FORDELETEASdeclare @id int,@ename va

关于触发器递归死循环的问题
CREATE TRIGGER delfiled on tablename1 FOR DELETE 
AS
declare @id int,@ename varchar(50),@strdrop varchar(200)

select @id=id from deleted

select @ename=ename from deleted

delete from tablename1 where fatherid=@id

set @strdrop='alter table tablename2 drop column '+@ename+''

exec (@strdrop)

这个触发器产生了死循环,怎样修改才能避免此循环,谢谢

[解决办法]

SQL code
CREATE TRIGGER delfiled  on tablename1 FOR  DELETE  AS IF @@ROWCOUNT = 0    RETURNdeclare @id int,@ename varchar(50),@strdrop varchar(200) select @id=id from deleted select @ename=ename from deleted delete from tablename1 where fatherid=@id set @strdrop= 'alter table tablename2  drop column   '+@ename+ ' ' exec (@strdrop) 

热点排行