数据表如下:
id content parentId
说明:id为主键,自增,content字符串类型,parentId整形(当为一级栏目时,parentId值为0)
现在如果删除某一节点内容,如何做递归呢,我想用存储过程实现,回答希望详细一些,偶是小菜
1select * from system_part order by id
2exec selpart
3create proc selpart
4as
5begin
6declare @id int
7declare @level int
8declare @t table(id int,[level] int)
9set @id=382
10set @level=1
11insert into @t values (@id,@level)
12while @@rowcount>0
13 begin
14 set @level=@level+1
15 insert into @t
16 select a.id,@level
17 from system_part as a
18 join @t as b on a.parentid=b.id where b.[level]=@level-1
19
20 end
21select * from system_part where id in (select id from @t)
22end
Create Procedure SP_GetSubID(ID int)
as
begin
Declare @tmp_Table table(ID int)
Declare @Count int
insert into @tmp_Table
select ID from Table where ID = @ID
while(@RowCount <>0 )
begin
insert into @tmp_Table
select ID,ParentID
from Table A inner join @tmp_Table B
on A.ID = B.ParentID
end
select * from @tmp_Table
end
许多问题的的解决方法是
先是: 数据库解决,如果不行
数据库方+后台程序解决,如果还不行
数据库方+后台程序+页面JS解决,如果三方联合起来都解决不了,
就不用解决了!