日期:2014-05-18  浏览次数:20514 次

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


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

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

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

可以这样创建数据表
SQL code

if object_id('tbl_contents') is not null
    drop table tbl_contents;
go

create table tbl_contents
(
    cont_id int not null identity(1, 1) primary key, --内容主键
    cont_content nvarchar(max),                    --存储每个章节的内容
    chpt_id int not null
);
go

if 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_chapters
select 1, '第一章标题' union all
select 2, '第二章标题' union all
select 3, '第三章标题' union all
select 4, '第四章标题' union all
select 5, '第五章标题' union all
select 6, '第六章标题' union all
select 7, '第七章标题';
go

insert into tbl_contents(cont_content, chpt_id)
select '第一章内容', 1 union all
select '第二章内容', 2 union all
select '第三章内容', 3 union all
select '第四章内容', 4 union all
select '第五章内容', 5 union all
select '第六章内容', 6 union all
select '第七章内容', 7;
go