日期:2014-05-16 浏览次数:20837 次
--测试数据 DECLARE @tb Table([id] int,[col1] varchar(8),[col2] int) insert @tb select 1,'河北省',0 union all select 2,'邢台市',1 union all select 3,'石家庄市',1 union all select 4,'张家口市',1 union all select 5,'南宫',2 union all select 6,'坝上',4 union all select 7,'任县',2 union all select 8,'清河',2 union all select 9,'河南省',0 union all select 10,'新乡市',9 --删除河南北省及以下所有节点 ;with t as( select * from @tb where id IN(1) union all select a.* from @tb a ,t where a.col2=t.id ) DELETE TB FROM @tb TB WHERE TB.id IN( SELECT t.id FROM t ) SELECT * FROM @tb /* (10 行受影响) (8 行受影响) id col1 col2 ----------- -------- ----------- 9 河南省 0 10 新乡市 9 (2 行受影响) */