role='FK_BOOK_RELATIONS_PUBLISH') then alter table Book delete foreign key FK_BOOK_RELATIONS_PUBLISHend if; if exists(select 1 from sys.sysforeignkey where role='FK_BOOK_RELATIONS_STACK') then alter table Book delete foreign key FK_BOOK_RELATIONS_STACKend 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 Adminsterend if; if exists( select 1 from sys.systable where table_name='Book' and table_type in ('BASE', 'GBL TEMP')) then drop table Bookend 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 Publishend if; if exists( select 1 from sys.systable where table_name='Reader' and table_type in ('BASE', 'GBL TEMP')) then drop table Readerend if; if exists( select 1 from sys.systable where table_name='Stack' and table_type in ('BASE', 'GBL TEMP')) then drop table Stackend 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;
评论