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,那我也說不清支持幾層
|