SQL Server学习笔记:递归查询
--建立测试数据 create table dept(id int primary key,parent_id int,name nvarchar(20)) insert dept select 0,0,N'<全部>' union all select 1,0,N'财务部' union all select 2,0,N'行政部' union all select 3,0,N'业务部' union all select 4,0,N'市场部' union all select 5,4,N'销售部' union all select 6,4,N'MIS' union all select 7,6,N'UI' union all select 8,6,N'软件开发' union all select 9,8,N'内部开发' go --全部数据 -- select *from dept --删除测试数据 -- drop table dept declare @dept int set