当前位置: 代码迷 >> Sql Server >> 想把一本小说存入数据库,小说有目录,要求能够快速定位到各个章节,可以用什么方法?解决方案
  详细解决方案

想把一本小说存入数据库,小说有目录,要求能够快速定位到各个章节,可以用什么方法?解决方案

热度:51   发布时间:2016-04-27 13:24:30.0
想把一本小说存入数据库,小说有目录,要求能够快速定位到各个章节,可以用什么方法?
想把一本小说存入数据库,小说有目录,要求能够快速定位到各个章节,可以用什么方法? 


------解决方案--------------------
用户是怎么操作的呢?加载目录,然后点击对应的跳到当年章节?所有章节内容都在一个页面上?

你要的是起点上的那种效果吗?
------解决方案--------------------
假如你的小说如以下结构:

目录
第一章标题
第一章内容
第二章标题
第二章内容
第三章标题
第三章内容
第四章标题
第四章内容
第五章标题
第五章内容
第六章标题
第六章内容
第七章标题
第七章内容

可以这样创建数据表
SQL code
if object_id('tbl_contents') is not null    drop table tbl_contents;gocreate table tbl_contents(    cont_id int not null identity(1, 1) primary key, --内容主键    cont_content nvarchar(max),                    --存储每个章节的内容    chpt_id int not null);goif object_id('tbl_chapters') is not null    drop table tbl_chapters;go--创建章节表create table tbl_chapters(    chpt_id int not null primary key, --章节id    chpt_title nvarchar(50) not null  --章节标题);go--创建外键alter table tbl_contents    add constraint FK_CONTENT_CHAPTER foreign key(chpt_id) references tbl_chapters(chpt_id);go--插入测试数据insert into tbl_chaptersselect 1, '第一章标题' union allselect 2, '第二章标题' union allselect 3, '第三章标题' union allselect 4, '第四章标题' union allselect 5, '第五章标题' union allselect 6, '第六章标题' union allselect 7, '第七章标题';goinsert into tbl_contents(cont_content, chpt_id)select '第一章内容', 1 union allselect '第二章内容', 2 union allselect '第三章内容', 3 union allselect '第四章内容', 4 union allselect '第五章内容', 5 union allselect '第六章内容', 6 union allselect '第七章内容', 7;go
  相关解决方案