发日记散分,Sql初级设计实例:小说网

comszsoft 2008-08-05 11:28:56
希望大家多多支持我的博客,我以后会尽量多写些设计和性能相关的帖子
http://blog.csdn.net/comszsoft
------------------------------

发现csdn关于设计方面的帖子太少,上次看到一个网友发的帖子提问到,正好本人也维护了一个类似于小说网的网站,便写下来。表结构设计

的非常简单,只有6个表。
需要特别说明的一点是 图书内容的分页是以按章节来分页的,而不是通常我们常见的按全本来分页,根据经验,按章节来分页更灵活。
各个表的结构如下:

1.t_user 用户表

create table t_user
(
username varchar(50) primary key, -- 用户名
registertime datetime -- 注册时间
)


2.t_class 分类表(名字土了点,不过中国人都看的懂,只支持一级分类)

create table t_class
(
classid int primary key,
classname varchar(50)
)


3.t_book 图书表

create table t_book
(
bookid int identity(1,1) primary key,
bookname varchar(50), -- 书名
author varchar(50), -- 作者
classid int, -- 对应分类id,这里没有建立外键约束,属于个人习惯问题
readcount int, -- 阅读次数
replycount int, -- 评论次数
publishtime smalldatetime, -- 发布时间
lastupdatetime smalldatetime -- 最后更新时间
)
-- 索引
create index ix_classid on t_book(classid)
create index ix_bookname on t_book(bookname)
create index ix_author on t_book(author)


4.t_chapter 图书章节表

create table t_chapter
(
chapterid int identity(1,1) primary key,
chaptername varchar(50), -- 章节名
bookid int, -- 对应图书id
pagecount int -- 本章节所有内容页数
)
-- 索引
create index ix_bookid on t_chapter(bookid)


5.t_content 图书内容表

create table t_content
(
contentid int identity(1,1) primary key,
chapterid int, -- 对应章节id
pageindex int -- 内容所在页数,这里采用按章节来分页
)
-- 索引
create index ix_chapterid on t_content(chapterid)
create index ix_chapterid_pageindex on t_content(chapterid,pageindex)


6.t_reply 图书评论表

create table t_reply
(
replyid int identity(1,1) primary key,
replycontent varchar(1000), -- 评论内容
bookid int , -- 对应图书id
replyusername varchar(50), -- 评论人
replytime datetime -- 评论时间
)
-- 索引
create index ix_bookid on t_reply(bookid)


就像你所看到的,这是一个简单的设计实例。最开始的设计原则就是简单,所有频繁的查询都可以用到索引。
因为csdn上的设计实例实在太少,下次我会尝试写个稍微复杂点的实例。

...全文
143 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
mcdreamny 2011-06-22
  • 打赏
  • 举报
回复
回一个
hery2002 2008-08-06
  • 打赏
  • 举报
回复
呵呵,支持 :)
-狙击手- 2008-08-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wgzaaa 的回复:]
接分很是乐意
[/Quote]
king2842 2008-08-06
  • 打赏
  • 举报
回复
顶一个,谢谢楼主美意
jasonren 2008-08-06
  • 打赏
  • 举报
回复
接分and 学习
flylei009 2008-08-06
  • 打赏
  • 举报
回复
呵呵,支持
wynlc 2008-08-06
  • 打赏
  • 举报
回复
http://blog.csdn.net/comszsoft
去学习下
huangqing_80 2008-08-06
  • 打赏
  • 举报
回复
接分也是美德
yangao 2008-08-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 mskyp 的回复:]
支持~ 接分
[/Quote]
comszsoft 2008-08-06
  • 打赏
  • 举报
回复
谢谢各位捧场
xiaomeixiang 2008-08-06
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 szx1999 的回复:]
看日记接分
[/Quote]
等不到来世 2008-08-06
  • 打赏
  • 举报
回复
看日记接分
hero_girl 2008-08-06
  • 打赏
  • 举报
回复
哈哈,接分
Garnett_KG 2008-08-06
  • 打赏
  • 举报
回复
jfjfjf
mskyp 2008-08-06
  • 打赏
  • 举报
回复
支持~ 接分
水族杰纶 2008-08-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jc_liumangtu 的回复:]
回帖是种美德```
[/Quote]
jc_liumangtu 2008-08-06
  • 打赏
  • 举报
回复
回帖是种美德```
wgzaaa 2008-08-05
  • 打赏
  • 举报
回复
接分很是乐意
comszsoft 2008-08-05
  • 打赏
  • 举报
回复
5.t_content 图书内容表 ,竟然少了一个字段 content

create table t_content
(
contentid int identity(1,1) primary key,
content narchar(1024), -- 每页存1000汉字
chapterid int, -- 对应章节id
pageindex int -- 内容所在页数,这里采用按章节来分页
)
-- 索引
create index ix_chapterid on t_content(chapterid)
create index ix_chapterid_pageindex on t_content(chapterid,pageindex)

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧