首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql的树形构造的删除节点的存储过程

2013-08-09 
mysql的树形结构的删除节点的存储过程[colorblue][/color]CREATE PROCEDURE proc_delete_department(IN r

mysql的树形结构的删除节点的存储过程
[color=blue][/color]

CREATE PROCEDURE proc_delete_department(IN rootid int)begin       declare _level int DEFAULT 0;            DROP TABLE IF EXISTS temptab;            create table temptab(id int, level int);                     insert into temptab(id, level) values(rootid, _level);                REPEAT                     insert into temptab(id, level)          select root.id, _level+1                 from department root, temptab sub                 where root.parentId= sub.id and sub.level = _level;          set _level = _level + 1;            until ROW_COUNT() = 0              end REPEAT;      delete from department where  id in (select id from temptab);       DROP TABLE IF EXISTS temptab;            end;


department 表 id 和 parentId

热点排行