1.创建图书管理数据库
create database bookManager
on
(
name=bookManager_data,
filename='D:\SQL\bookManager_data.mdf',
size=5MB,
maxsize=100MB,
filegrowth=15%
)
log on
(
name=bookManager_log,
filename='D:\SQL\bookManager_log.ldf',
size=2MB,
filegrowth=1MB
)
2.数据库中增加数据文件
use bookManager
go
alter database bookManager
add file
(
name = bookManager_ndata,
filename = 'D:\SQL\bookManager_ndata.ndf',
size=5MB,
maxsize=100MB,
filegrowth=15%
)
3.删除数据库
drop database bookManager
即:drop database 数据库名
4.修改数据库名
exec sp_renamedb 'bookManager','bm'
即:exec sp_renamedb '原数据库名','新数据库名'
5.创建图书、读者、借阅三个基本表的表结构,并适当加入约束
use bookManager
go
create table books
(
bookId int primary key,--主键约束
bookStyle varchar(30),
bookName varchar(30),
bookWritter varchar(10),
bookPublish varchar(30),
bookPrice int
)
create table reader
(
readerId int primary key,--主键约束
readerDepartment varchar(10),
readerName varchar(10),
readerSex varchar(2),
readerTitle varchar(10),
readerAddress varchar(30)
)
create table borrow
(
readerId int,
bookId int,
checkInTime varchar(30),
constraint FK_readerId foreign key(readerId) references reader(readerId),--外键约束
constraint FK_bookId foreign key(bookId) references books(bookId)--外键约束
)
go
6.删除表
drop table books
即:drop table 表名
7.修改表名
exec sp_rename 'books','book'
即:exec sp_rename '原表名','新表名'
8.向表中插入数据
Insert Into Books values ('445501','TP3/12','数据库导论','王强','科学出版社',17.90 )
Insert Into Books values ('445502','TP3/12','数据库导论','王强','科学出版社',17.90 )
Insert Into Books values ('445503','TP3/12','数据库导论','王强','科学出版社',17.90 )
Insert Into Books values ('332211','TP5/10','计算机基础','李伟','高等教育出版社',18.00 )
Insert Into Books values ('112266','TP3/12','FoxBASE','张三','电子工业出版社',23.60 )
Insert Into Books values ('665544','TS7/21','高等数学','刘明','高等教育出版社',20.00 )
Insert Into Books values ('114455','TR9/12','线性代数','孙业','北京大学出版社',20.80 )
Insert Into Books values ('113388','TR7/90','大学英语','胡玲','清华大学出版社',12.50 )
Insert Into Books values ('446601','TP4/13','数据库基础','马凌云','人民邮电出版社',22.50 )
Insert Into Books values ('446602','TP4/13','数据库基础','马凌云','人民邮电出版社', 22.50)
Insert Into Books values ('446603','TP4/13','数据库基础','马凌云','人民邮电出版社',22.50 )
Insert Into Books values ('449901','TP4/14','FoxPro大全','周虹','科学出版社',32.70 )
Insert Into Books values ('449902','TP4/14','FoxPro大全','周虹','科学出版社',32.70 )
Insert Into Books values ('118801','TP4/15','计算机网络','黄力钧','高等教育出版社',21.80 )
Insert Into Books values ('118802','TP4/15','计算机网络','黄力钧','高等教育出版社',21.80 )
Insert Into Reader values('111','信息系','王维利','女','教授','1号楼424')
Insert Into Reader values('112','信息系','李立','男','副教授','2号楼316')
Insert Into Reader values('113','经济系','张三','男','讲师','3号楼105')
Insert Into Reader values('114','信息系','周华发','男','讲师','1号楼316')
Insert Into Reader values('115','信息系','赵正义','男','工程师','1号楼224')
Insert Into Reader values('116','计算机系','李明','男','副教授','1号楼318')
Insert Into Reader values('117','计算机系','李小峰','男','副教授','1号楼214')
Insert Into Reader values('118','计算机系','许鹏飞','男','助工','1号楼216')
Insert Into Reader values('119','国际贸易','刘大龙','男','讲师','1号楼318')
Insert Into Reader values('120','国际贸易','李雪','女','讲师','4号楼506')
Insert Into Reader values('121','国际贸易','李爽','女','讲师','4号楼510')
Insert Into Reader values('122','财会系','王纯','女','助教','4号楼512')
Insert Into Reader values('123','财会系','沈小霞','男','副教授','2号楼202')
Insert Into Reader values('124','财会系','朱海','男','副教授','2号楼210')
Insert Into Reader values('125','信息系','马英明','男','助教','2号楼212')
Insert into Borrow values('112','445501','1997-3-19')
Insert into Borrow values('125','332211','1997-2-12')
Insert into Borrow values('111','445503','1997-8-21')
Insert into Borrow values('112','112266','1997-3-14')
Insert into Borrow values('114','665544','1997-10-2')
Insert into Borrow values('120','114455','1997-11-2')
Insert into Borrow values('120','118801','1997-10-18')
Insert into Borrow values('119','446603','1997-12-12')
Insert into Borrow values('112','449901','1997-10-23')
Insert into Borrow values('115','449902','1997-8-21')
Insert into Borrow values('118','118801','1997-9-10')