随记sqlserver学习笔记

create database libraryDB
go
use libraryDB
go
--读者信息表
create table ReaderInfo(
ReaderId int not null primary key identity,--读者编号,表示列、自动增长,主键
ReaderNo varchar(20) not null ,--借书证号
ReaderName varchar(10) not null,--姓名
Sex int default 0,--性别,0:男,1:女
BirthDate datetime,--出生日期
Phone varchar(50),--联系电话
NumberID varchar(30),--身份证号
Address varchar(200),--家庭地址
RegisterDate datetime ,--登记日期
ReaderCount int default 0,--借阅次数
Remark varchar(500) ,--备注信息
IsLoss int default 0--是否挂失,0:没有挂失,1:挂失
)
insert into ReaderInfo values('ls001','黎明',default,'1988-10-3','58501534','500101198810037412','重庆沙坪坝区','2017-03-25',default,'我以后终于可以借书了哟',default)
insert into ReaderInfo values('ls002','大发',default,'1988-7-3','52501934','50010119880703593x','重庆市渝北区','2017-03-25',default,'我一定要多看看书',default)
select * from ReaderInfo
--图书类型表
create table BookType(
TypeId int not null primary key identity,--图书类型编号,表示列、自动增长,主键
TypeName varchar(50)not null,--图书类型名称
Remark varchar(100) --备注信息
)

--图书信息表
create table BookInfo(
BookId int not null primary key identity,--图书编号,表示列、自动增长,主键
BookName varchar(50)not null,--图书名称
TypeId int not null references BookType(TypeId),--图书类型编号,外键
Author varchar(20) ,--作者
Press varchar(50),--出版社
PressDate datetime ,--出版日期
Price money ,--价格
Page int ,--页数
NowNum int ,--现存量
BookNum int ,--库存总量
AddDate datetime ,--入库时间
ByCount int default 0,--借出次数
IsOff int default 0,--是否注销,0:没有注销,1:注销
Remark varchar(500) ,--图书简介

)

--图书借阅表
create table BorrowInfo(
BorrowId int not null primary key identity,--借阅编号,表示列、自动增长,主键
BookId int not null references BookInfo(BookId),--图书编号,外键
ReaderId int not null references ReaderInfo(ReaderId),--读者编号,外键
BorrowTime datetime ,--借阅时间
ShouldTime datetime ,--应还时间
MortgageMoney money,--押金
BorrowState int default 0,--借阅状态,0:新借,1:未还,2:已还
)

--图书归还表
create table BackInfo(
BackId int not null primary key identity,--借阅编号,表示列、自动增长,主键
BookId int not null references BookInfo(BookId),----图书编号,外键
ReaderId int not null references ReaderInfo(ReaderId),--读者编号,外键
BackMoney money,--退还押金
EndTime datetime,--归还时间
IsBack int default 0--确定归还,0:归还,1:为归还
)

猜你喜欢

转载自www.cnblogs.com/zqw111/p/10826709.html