删除父节点下的子节点 存储过程版 新手需多看几遍 create function dbo.aa(@i int) returns @t table(ml_id int,parent_id int,level int) as begin declare @level int set @level=0 insert into @t select ml_id,parent_id,@level from dbo.T_TEMP_MuLu where dbo.T_TEMP_MuLu.ml_id=@i while @@rowcount> 0 begin set @level=@level+1 insert into @t select a.ml_id,a.parent_id,@level from dbo.T_TEMP_MuLu a left join @t b on a.parent_id=b.ml_id where b.level=@level-1 end return end delete dbo.T_TEMP_MuLu where ml_id in (select ml_id from dbo.aa(49)) drop function aa truncate table dbo.T_TEMP_MuLu insert into dbo.T_TEMP_MuLu SELECT [ML_ID] ,[Parent_ID] ,[FolderFlag] ,[ML_Name] ,[BaoShi] ,[Dept] ,[ZiLiaoHe] ,[BZ] FROM [DB_TOPPING].[dbo].[T_YingJian] set @level=@level+1 insert into @t select a.ml_id,a.parent_id,@level from dbo.T_TEMP_MuLu a left join @t b on a.parent_id=b.ml_id where b.level=@level-1 end return end delete dbo.T_TEMP_MuLu where ml_id in (select ml_id from dbo.aa(49)) drop function aa truncate table dbo.T_TEMP_MuLu insert into dbo.T_TEMP_MuLu SELECT [ML_ID] ,[Parent_ID] ,[FolderFlag] ,[ML_Name] ,[BaoShi] ,[Dept] ,[ZiLiaoHe] ,[BZ] FROM [DB_TOPPING].[dbo].[T_YingJian]