sql存储过程删除无限极分类

拈花ヽ惹草 提交于 2019-12-25 18:59:22


create procedure pro_delete
@deleteId int
as
declare @nodeid int
declare @id int
declare @pid int
set @nodeid = @deleteId
set @id = @nodeid
set @pid = @nodeid
begin transaction
while(exists (select * from H where id = @nodeid))
begin
        if(exists (select * from H where Pid = @id and id != @id) )
        begin
                set @pid = @id
                set @id = (select top 1 id from H where pid = @id and id != @id)
        end
        else
        begin
                print @id
                delete from H where id = @id
                set @id = @pid
                set @pid = (select top 1 pid from H where id = @pid)
        end
end
if(@@ERROR<>0)
 ROLLBACK TRANSACTION
else
 commit transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!