΢ͻӦ
MICROCOMPUTER & ITS APPLICATIONS
1999 18 1 Vol.18 No.1 1999



һڹϵݿͼıʾ
Զ
ժҪݿӦóоһѯ1ڹϵݿжͼбʾͱķʹMS SQL Server 6.5T-SQLʵ˱̡
ؼʣϵݿ⡡ͼıSQL
ĿǰӦó漰ݿӦãڶݿвѯʱһΪӵ⡣磬֪֮ĺ࣬Ҫĳһеһе·ѯӱ漰ͼͨԺؼ·⣬ǶͼıͼıһҪӦø߼Եָݽṹʵ֡ڴݿӦó򿪷ʵȽѡһ1ڹϵݿбʾͼķԼñ׼SQLԶб㷨ͨһʵ˵
1ͼıʾ
1.ͼıʾ
ͼΪͼԱʾΪ˫ͼͳ϶ͼıʾһڽӱȶַʽڹϵݿֻԶάʽ洢ݡ˱ķǽͼʾΪ2ά1ǽڵ(node)ڵnodenameڵϢnodeinfoǷΪڵynroot(ڵΪ1Ϊ0ͼȫΪ1)3ֶΣ1뻡йصĻ(arc)ʼڵstartnodeֹڵendnode뻡йصϢarcinfo 3ֶΡṹ12ʾ
1nodeṹ

nodenamenodeinfoynroot
charcharint

2arcṹ

startnodeendnodearcinfo
charcharchar

2.ͼı
㷨Ϊ㷨ͼͼ1ʾõ2ʱstacklist,stackΪջʹãʱŷص㣬list¼ѷʹĽڵ㡣stackаnodenameglevel 2ֶΣlistаnodenamesequence 2ֶΡ 

ͼ1㷨ͼ
2ʵ
ͼ2еͼΪͼݿд洢Ϊ3ͱ4

ͼ2ͼ
3node

nodenameynroot
a1
b0
c0
d0
e0
f0
g0
h0

4Arc

startnodeendnode
ab
ac
bd
dg
dh
cf
eb
he

ĲMS SQL Server 6.5T-SQLԱд̶ͼ2б£
set nocount on
declare @i int,@j int,@nodename char(1)
create table #stack(node char(1),glevel int)
create table #list(node char(1),sequence int)
insert into #stack select *from node where ynroot=1
select @i=1
select @j=1
while @i>0
begin
if exists(select *from #stack where glevel=@i)
begin
select @nodename=node
from #stack where glevel=@i
delete from #stack where glevel=@i and node=@nodename
if exists(select *from #list where node=@nodename)
continue
insert #list values(@nodename,@j)
select @j=@j+1
insert #stack
select endnode,@i+1
from arc where startnode=@nodename
if @@rowcount>0
select @i=@i+1
end
else
select @i=@i-1
end
select * from #list
ͼ3 
nodesequence

a1
b2
d3
g4
h5
e6
c7
f8
ͼ3
ʹü򵥵ݽṹͱ׼SQLʵ˶ͼıڽʵĸӲѯһĲοֵ
ߵλѧѧԺ947#(300072)
ο
1εΰ.ݽṹ.廪ѧ磬1992
2Microsoft Corporation.Microsoft SQL SERVER Database Developer's Companion.
(ոڣ1998-07-25)
