use Library
go
if exists(select * from sysobjects where name='Book')
drop table Book
create table Book   --图书信息表Book
(
 BID char(8) not null, --图书编号,该栏必填
 BName varchar(20) not null, --图书书名,该栏必填
 Author char(8), --作者姓名
 PubComp varchar(20), --出版社
 PubDate datetime, --出版日期
 BCount int, --现存数量
 Price int --单价
)
go
alter table Book
add constraint PK_bid primary key (BID) --主键
alter table Book
add constraint CK_bid check (BID like 'ISBN%') --必须以ISBN开头
alter table Book
add constraint CK_pubdate check (PubDate<getdate()) --必须小于当前日期
alter table Book
add constraint CK_bcount check (BCount>=1) --必须大于等于1
alter table Book
add constraint CK_price check (Price>0) --必须大于0
go
其他表中的BIF是 BID的外键
现在想在Book表中添加一列 “BTotal”列,数据类型int,用于保存每种图书的馆藏总量