日期:2014-05-18 浏览次数:20686 次
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