当前位置: 移动技术网 > IT编程>开发语言>.net > bbs树型结构的实现方法(二)

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

2019年01月13日  | 移动技术网IT编程  | 我要评论

尹峰简历,丫头不吃庶,egold

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数*/
prima(最完善的虚拟主机管理)ry 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,那我也说不清支持几层


如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网