/*==============================================================*/
/* Database name: library */
/* DBMS name: MySQL 5.0 */
/* Created on: 2008-11-8 12:51:39 */
/*==============================================================*/
drop database if exists library1;
/*==============================================================*/
/* Database: library1 */
/*==============================================================*/
create database library1;
use library1;
/*==============================================================*/
/* Table: tb_ReaderType */
/*==============================================================*/
create table tb_ReaderType
(
readertypeID int not null primary key auto_increment,
typeName varchar(50) not null,
canborowcount numeric(2,0) not null
);
/*==============================================================*/
/* Table: tb_bookDetailsInfo */
/*==============================================================*/
create table tb_bookDetailsInfo
(
bookTypeID int not null ,
bookID int not null primary key auto_increment,
isbn varchar(50) unique not null,
bookName varchar(50) not null,
authorName varchar(50),
publisherName varchar(50),
publisherTime date,
bookPrice float(3,1),
remark varchar(1000)
);
/*==============================================================*/
/* Table: tb_bookShelfInfo */
/*==============================================================*/
create table tb_bookShelfInfo
(
bookShelfID int not null primary key auto_increment,
bookShelfName varchar(50) unique not null
);
/*==============================================================*/
/* Table: tb_bookType */
/*==============================================================*/
create table tb_bookType
(
bookTypeID int not null primary key auto_increment,
bookTypeName varchar(50) unique not null,
canBrowDays numeric(3,0) not null,
bookShelfID int not null
);
/*==============================================================*/
/* Table: tb_borowsBookInfo */
/*==============================================================*/
create table tb_borowsBookInfo
(
bookID int not null,
readerID int not null,
barcode varchar(50) not null,
isbn varchar(50) not null,
browTime date not null,
givebackTime date not null
);
/*==============================================================*/
/* Table: tb_forfeiture */
/*==============================================================*/
create table tb_forfeiture
(
payMoneyOneday float(3,0)
);
/*==============================================================*/
/* Table: tb_libraryInfo */
/*==============================================================*/
create table tb_libraryInfo
(
libraryName varchar(50),
address varchar(50),
Email varchar(50),
curatorName varchar(50),
createTime date,
remark varchar(2000)
);
/*==============================================================*/
/* Table: tb_managerDetailsInfo */
/*==============================================================*/
create table tb_managerDetailsInfo
(
managerID int not null primary key auto_increment,
managerName varchar(50) unique not null,
managerPassword varchar(50) not null,
roleID int not null
);
/*==============================================================*/
/* Table: tb_managerRoles */
/*==============================================================*/
create table tb_managerRoles
(
roleID int not null primary key auto_increment,
roleName varchar(50) unique not null,
rolePower int not null
);
/*==============================================================*/
/* Table: tb_readerBorowInfo */
/*==============================================================*/
create table tb_readerBorowInfo
(
barcode varchar(50) not null,
readerID int not null,
borowedCount numeric(3,0) not null,
canborowCount numeric(3,0) not null,
primary key (barcode)
);
/*==============================================================*/
/* Table: tb_readerDetailsInfo */
/*==============================================================*/
create table tb_readerDetailsInfo
(
readertypeID int not null,
readerID int not null primary key auto_increment,
readerName varchar(50) not null,
phone varchar(20),
Email varchar(50),
certificatetype varchar(50) not null,
zhenjianno varchar(50) unique not null,
barcode varchar(50) unique not null,
isreportloss bool,
sex char(2) not null,
remark varchar(1000)
);
/*==============================================================*/
/* Table: tb_bookborowedcount */
/*==============================================================*/
create table tb_bookborowedcount(
borowedCount numeric(5,0) not null default 0 ,
bookID int not null
);
alter table tb_bookborowedcount add constraint FK_bookborrowed_bookdetails foreign key (bookID)
references tb_bookdetailsinfo (bookID) on delete restrict on update restrict;
alter table tb_bookDetailsInfo add constraint FK_booktypetypeID_bookdetailstypeID foreign key (bookTypeID)
references tb_bookType (bookTypeID) on delete restrict on update restrict;
alter table tb_bookType add constraint FK_booktypeshelfID_bookshelfbookshelfID foreign key (bookShelfID)
references tb_bookShelfInfo (bookShelfID) on delete restrict on update restrict;
alter table tb_borowsBookInfo add constraint FK_bookdetails_bookborows foreign key (bookID)
references tb_bookDetailsInfo (bookID) on delete restrict on update restrict;
alter table tb_borowsBookInfo add constraint FK_readerdetailsbarcode_borrowbookbarcode foreign key (readerID)
references tb_readerDetailsInfo (readerID) on delete restrict on update restrict;
alter table tb_managerDetailsInfo add constraint FK_rolesrolesID_roleMemberrolesID foreign key (roleID)
references tb_managerRoles (roleID) on delete restrict on update restrict;
alter table tb_readerBorowInfo add constraint FK_包括 foreign key (readerID)
references tb_readerDetailsInfo (readerID) on delete restrict on update restrict;
alter table tb_readerDetailsInfo add constraint FK_readertypetypeID_readersredertypeID foreign key (readertypeID)
references tb_ReaderType (readertypeID) on delete restrict on update restrict;
==========================================================================================
下面的有问题都不要
//这句有问题错误的外键约束
alter table tb_bookdetailsinfo add column bookstatus bool default 1;
alter table tb_readerDetailsInfo drop column bookstatus;
alter table tb_readerDetailsInfo add constraint FK_属于 foreign key (barcode)
- 1
- 2
- 3
前往页