日期:2014-05-18 浏览次数:20659 次
--外关键字增加级联删除、级联更新 alter table 表 add constraint fk_name foreign key(约束列) references 主表(约束列) on update cascade on delete no action
------解决方案--------------------
这个应该不是级联来处理的事,楼主自己写语句来处理了。
1、递归找到该节点下所有子节点,例如按公司来看
;with cte as
(
select id,parentid from SM_Company where id = 2 --要删除的公司节点
union all
select a.id,a.parentid
from SM_Company a join cte b on a.parentid = b.id
where a.id is not null
)