bbs树型结构的实现方法(二)

bigeagle】 于 2000-12-6 14:43:38 加贴在 Joy ASP ↑:

下面这种方法是大怪兽和怡红公子现在采用的方法

create table forum
(
ID int NOT NULL IDENTITY,/帖子序列号/
rootID int NOT NULL, /根帖子序列号/
parentID int NOT NULL default=0,/双亲帖子序列号/
indent tinyint,/缩进/
order tinyint,/同主题帖子排序/
username varchar(40) NOT NULL,/用户名/
time daytime NOT NULL,/贴帖子时间/
IP varchar(15) NOT NULL,/发帖子的IP/
subject varchar(60) NOT NULL,/帖子题目/
text text,/帖子正文/
bytes int,/帖子字数/
status bit,/状态/
hits tinyint,/hit数/
primary key(ID) /主关键字/
)

简单地说用3个列描述层次结构
1.rootid 2.indent 3.同一个root下,order_no

1号贴
2号贴
3号贴
5号贴
4号贴
6号贴

这个结构的存储格式如下
id rootid indent 一个root下,order_no
1 1 0 0
2 1 1 1
3 1 2 2
4 4 0 0
5 1 1 3
6 4 1 1

按rootid,"一个root下,order_no"排序,
按indent缩进
即得树状到帖子列表

indent是4byte整数,从0开始的话,支持2147483648层
你要是定成numberic,那我也说不清支持几层

Published At
Categories with Web编程
Tagged with
comments powered by Disqus