我的数据库是sql2000的 ;with cte1 as
(select * from t_folder where FolderId ='D040E2ED-253E-45C3-B8FF-C1605244525B'
union all
select * from t_folder a inner join cte1 b on a.ParentId=a.FolderId
)
delete from t_folder where FolderId in(select FolderId from cte1)貌似2000不支持with,那么SQL2000中我如何递归删除呢?
字段
FolderId FolderName ParentId ...
(select * from t_folder where FolderId ='D040E2ED-253E-45C3-B8FF-C1605244525B'
union all
select * from t_folder a inner join cte1 b on a.ParentId=a.FolderId
)
delete from t_folder where FolderId in(select FolderId from cte1)貌似2000不支持with,那么SQL2000中我如何递归删除呢?
字段
FolderId FolderName ParentId ...
drop proc 存储过程名
with cte1...,
union all,
inner join ,
in(...),
都知道,而且一起用但是呢,明明可以一句话轻松的解决的问题
你居然写出这么复杂的语句,所以说,
sql语句不仅要知道怎么用,而且要灵活用,
适当的用
我不是不写,而是不懂你的题意,你把表结构列出来,
还有你想要达到的效果也就是问题说出来
cte1里面又包含cte1 我已经凌乱,我认为你sql写的很有问题
还是这样说吧,你把表结构和问题说出来再看看
(
folderID int
)declare @temp table
(
folderID int
)
declare @temp1 table
(
folderID int
)
insert into @temp (folderID)
select folderID
from t_folder
where FolderId ='D040E2ED-253E-45C3-B8FF-C1605244525B'while(exists(select * from @temp))
begin
insert into @folderID(folderID) select folderID from @temp
insert into @temp1(folderID) select folderID from @temp
delete from @temp
select folderID from t_folder where parentID in(select folderID from @temp1)
delete from @temp1
end
sql server2000中好像只能用循环,这样不知道行不行
2000里面不支持其实很简单 关键是我现在的ID是GUID的类型 跟INT类型不一样 转的有点闷 表结构就是
id name pid 2个ID都是GUID类型 根目录节点pid为null
选中一个节点点击删除
如果她下面有子节点也要删除 或者反着来也可以 要删除父节点 必须删除子节点程序我实现了 效率肯定不如存储过程
而是在程序里递归效率上差别不大,不要为了那么一点小性能来让自己在sql中编写复杂逻辑,
程序里完全能实现