--写如下处理函数 create function f_cid( @id int )returns @re table(ProductClass_ID int,[level] int) as begin declare @l int set @l=0 insert @re select @id,@l while @@rowcount>0 begin set @l=@l+1 insert @re select a.ProductClass_ID,@l from ProductClass a,@re b where a.Parent_ID=b.ProductClass_ID and b.[level]=@l-1 end return end go--删除某个id使用下面的语句,删除id=2的: delete a from ProductClass a,f_cid(2) b where a.ProductClass_ID =b.ProductClass_ID
create function f_cid(
@id int
)returns @re table(ProductClass_ID int,[level] int)
as
begin
declare @l int
set @l=0
insert @re select @id,@l
while @@rowcount>0
begin
set @l=@l+1
insert @re select a.ProductClass_ID,@l
from ProductClass a,@re b
where a.Parent_ID=b.ProductClass_ID and b.[level]=@l-1
end
return
end
go--删除某个id使用下面的语句,删除id=2的:
delete a from ProductClass a,f_cid(2) b where a.ProductClass_ID =b.ProductClass_ID