accp7.0-s2 优化MySchool数据库

来源:互联网 发布:c语言共用体union例子 编辑:程序博客网 时间:2024/05/19 23:52
drop database LibraryCREATE DATABASE Libraryon primary (name='Library1',filename='e:\Library1.mdf',size=5mb,filegrowth=15%)log on(name='Library2',filename='e:\Library1_log.ldf',size=5mb,maxsize=50,filegrowth=1)create table Book(BID nvarchar not null,--图书编号 非空BName nvarchar not null,--图书名 非空Author nvarchar not null,--作者姓名PubComp nvarchar not null ,--出版者PubDate datetime not null,--出产日期BCount int not null ,--存货数量Price money not null,--单价)create table Reader (RID nvarchar not null,--读者编号RName nvarchar not null,--读者姓名LendNum int not null,--结束数量RAddress nvarchar not null,--联系地址)create table Borrow (RID nvarchar not null,--读者编号 复合主键 BID nvarchar not null,--图书编号.复合主键LendDate datetime not null ,--借阅日期,复合主键willDate datetime not null,--应还日期,ReturnDate datetime  null,--实际归还日期 )create table Penalty (RID nvarchar not null,--读者标号,复合主键BID nvarchar not null,--图书编号,复合主键PDate datetime not null,--罚款日期,复合主键PType int not  null,--罚款类型 1-延期 2-损坏 3-丢失Amount money not null--罚款金额)alter table book  add constraint pk_bid1 primary key(bid)  alter table book  add constraint ck_bid check(bid like 'isbn%')  alter table book  add constraint ck_pubdate check(pubdate<=getdate())  alter table book  add constraint ck_bcount check(bcount>=1)  alter table book  add constraint ck_price check(price>0)  alter table reader  add constraint pk_rid1 primary key(rid)  alter table reader  add constraint ck_lendnum check(lendnum>=0)  alter table borrow  add constraint pk_rid2 primary key(rid,bid,lenddate)  alter table borrow  add constraint fk_rid1 foreign key(rid) references reader(rid)  alter table borrow  add constraint fk_bid1 foreign key(bid) references book(bid)  alter table borrow  add constraint df_lenddate default(getdate()) for lenddate  alter table borrow  add constraint ck_willdate check(willdate>=getdate())  alter table borrow  add constraint df_willdate default(dateadd(month,1,getdate())) for willdate  alter table borrow  add constraint df_returndate default(null) for returndate  alter table penalty  add constraint pk_rid3 primary key(rid,bid,pdate)  alter table penalty  add constraint fk_rid2 foreign key(rid) references reader(rid)  alter table penalty  add constraint fk_bid2 foreign key(bid) references book(bid)  alter table penalty  add constraint df_pdate default(getdate()) for pdate  alter table penalty  add constraint ck_ptype check(ptype=1 or ptype=2 or ptype=3)  alter table penalty  add constraint ck_amount check(amount>0)  alter table book add btotal int  

0 0
原创粉丝点击