01、数据库概念设计
1. 数据库表设计
管理员表admin:管理员编号(admin_id),管理员姓名(admin_name),密码(admin_password),登录次数(logins),最后一次登录时间(lastlogin)和权限(right)。
读者表reader:读者编号(reader_id),读者姓名(reader_name),性别(sex),年龄(age),班级(class),最大借书量(maxborrowed)借书总量(amount)和权限(right)。
书籍表books:书籍编号(book_id),书名(title),作者(author),出版社(book concert),价格(price),出版时间(time),在库总量(amount),剩余量(remain)。
借阅信息表(borrow_information):书籍编号(book_id),读者编号(reader_id),借书时间(borrow_time),到期时间(end_time),归还时间(return_time)。
预订信息表:读者编号(reader_id),书籍编号(book_id),预订时间(reservation_time),取消预订时间(reservationcanceltime)。
书籍类型表booktype:书籍类型编号(type_id),书籍类型名称(type_name)。
用户权限表right:权限(right)。
2. 图书管理系统实体之间的E-R图
▍图12.13 图书馆管理系统各实体之间的ER图
3. 基于powerdesigner的CDM数据库模型
据库逻辑结构图如下图,该图显示了各实体的属性及各实体之间的关系。
▍图12.13 数据库逻辑结构图
02、数据字典
1. 图书管理系统数据库表格清单
2. 图书管理系统数据库表格列清单
3. 表格书库
表格书库的卡片
实体书库的属性的清单
4. 表格借还书
表格借还书的卡片
实体借还书的属性的清单
5. 表格出版社
表格出版社的卡片
实体出版社的属性的清单
6. 表格图书
表格图书的卡片
实体图书的属性的清单
- 表格管理员
表格管理员的卡片
实体管理员的属性的清单
8. 表格读者
表格读者的卡片
实体读者的属性的清单
▍图12.14数据库物理设计
04、数据库物理代码
role='FK_BOOK_RELATIONS_PUBLISH') then
alter table Book
delete foreign key FK_BOOK_RELATIONS_PUBLISH
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_BOOK_RELATIONS_STACK') then
alter table Book
delete foreign key FK_BOOK_RELATIONS_STACK
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_BORROW B_RELATIONS_READER') then
alter table "Borrow Book"
delete foreign key "FK_BORROW B_RELATIONS_READER"
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_BORROW B_RELATIONS_BOOK') then
alter table "Borrow Book"
delete foreign key "FK_BORROW B_RELATIONS_BOOK"
end if;
if exists(
select 1 from sys.systable
where table_name='Adminster'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table Adminster
end if;
if exists(
select 1 from sys.systable
where table_name='Book'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table Book
end if;
if exists(
select 1 from sys.systable
where table_name='Borrow Book'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table "Borrow Book"
end if;
if exists(
select 1 from sys.systable
where table_name='Publish'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table Publish
end if;
if exists(
select 1 from sys.systable
where table_name='Reader'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table Reader
end if;
if exists(
select 1 from sys.systable
where table_name='Stack'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table Stack
end if;
/*==============================================================*/
/* Table: Adminster */
/*==============================================================*/
create table Adminster
(
AdminID char(8) not null,
AdminName varchar(8) not null,
Phonenumber varchar(11) not null,
AdminPassword varchar(20) not null,
constraint PK_ADMINSTER primary key (AdminID)
);
/*==============================================================*/
/* Table: Book */
/*==============================================================*/
create table Book
(
BookID char(10) not null,
PublishName varchar(40) null,
StackID char(2) null,
ISBN varchar(20) not null,
Title varchar(40) not null,
Author varchar(20) null,
Price numeric(5,2) not null,
"Book concern" varchar(40) null,
AddTime date not null,
Amount integer not null,
Remain integer not null,
constraint PK_BOOK primary key (BookID)
);
/*==============================================================*/
/* Table: "Borrow Book" */
/*==============================================================*/
create table "Borrow Book"
(
ReaderID char(10) null,
BookID char(10) null,
BorrowTime date null,
SReturntime date null,
RReturntime date null
);
/*==============================================================*/
/* Table: Publish */
/*==============================================================*/
create table Publish
(
PublishName varchar(40) not null,
Address varchar(40) not null,
Phone varchar(15) not null,
"E-mail" varchar(30) not null,
constraint PK_PUBLISH primary key (PublishName)
);
/*==============================================================*/
/* Table: Reader */
/*==============================================================*/
create table Reader
(
ReaderID char(10) not null,
ReaderName varchar(8) not null,
Sex char(2) null,
Age integer null,
Class varchar(10) not null,
ReaderPassword varchar(20) not null,
Maxborrowed integer not null,
constraint PK_READER primary key (ReaderID)
);
/*==============================================================*/
/* Table: Stack */
/*==============================================================*/
create table Stack
(
StackID char(2) not null,
StackName varchar(10) not null,
StackLocation varchar(20) not null,
constraint PK_STACK primary key (StackID)
);
alter table Book
add constraint FK_BOOK_RELATIONS_PUBLISH foreign key (PublishName)
references Publish (PublishName)
on update restrict
on delete restrict;
alter table Book
add constraint FK_BOOK_RELATIONS_STACK foreign key (StackID)
references Stack (StackID)
on update restrict
on delete restrict;
alter table "Borrow Book"
add constraint "FK_BORROW B_RELATIONS_READER" foreign key (ReaderID)
references Reader (ReaderID)
on update restrict
on delete restrict;
alter table "Borrow Book"
add constraint "FK_BORROW B_RELATIONS_BOOK" foreign key (BookID)
references Book (BookID)
on update restrict
on delete restrict;