问题描述
创建学校图书馆数据库BookDB
1、创建学校图书馆信息管理系统数据库BookBD
2、学校图书馆借书信息管理系统建立三个表:
学生信息表:student
字段名称
数据类型
说明
stuID
char(10)
学生编 ,主键
stuName
Varchar(10)
学生名称
major
Varchar(50)
专业
图书表:book
字段名称
数据类型
说明
BID
char(10)
图书编 ,主键
title
char(50)
书名
author
char(20)
借书信息表:borrow
字段名称
数据类型
说明
borrowID
char(10)
借书编 ,主键
stuID
char(10)
学生编 ,外键
BID
char(10)
图书编 ,外键
T_time
datetime
借书日期
B_time
datetime
还书日期
3、为每张表添加相应约束
4、为每张表插入测试数据,验证表的正确性
八、创建学生信息数据库StuDB
学生成绩信息三个表,结构如下:
学生表:Member
字段名称
数据类型
说明
MID
Char(10)
学生 ,主键
MName
Char(50)
姓名
课程表:
字段名称
数据类型
说明
FID
Char(10)
课程,主键
FName
Char(50)
课程名
成绩表:Score
字段名称
数据类型
说明
SID
int
自动编 ,主键,成绩记录
FID
Char(10)
课程 ,外键
MID
Char(10)
学生 ,外键
Score
int
成绩
创建StuDB数据库
创建三张数据表
为每张表添加约束
代码:
if exists (select *from sysdatabases where name=’bookDB’)
drop database bookDB
create database bookDB
on primary–主数据库文件
(
name = ‘bookDB’,
filename =’D:projectbookDB.mdf’,
size=5mb,
maxsize=100mb,
filegrowth=2mb
)
————————学生信息表:student———————–
if exists (select *from sysobjects where name=’student’)
drop table student
create table student
(
stuIDchar(20)not null primary key,–学生编 ,主键
stuNameVarchar(10)not null,–学生名称
majorVarchar(50)not null,–专业
)
————————–图书表:book—————————
if exists (select *from sysobjects where name=’book’)
drop table book
create table book
(
BIDchar(10)not null primary key,–图书编 ,主键
titlechar(50)not null,–书名
)
—————借书信息表:borrow—————
if exists (select *from sysobjects where name=’borrow’)
drop table borrow
create table borrow
(
borrowID char(10)not null primary key,–借书编 ,主键
stuID char(20)references student(stuID)not null,–学生编 ,外键
BIDchar(10)references book(BID)not null,–图书编 ,外键
T_timedatetime not null,–借书日期
B_timedatetime not null,–还书日期
)
–日期默认为系统当前日期
alter table borrow
add constraint DF_T_time default(getdate())for T_time
alter table borrow
add constraint DF_B_time default(getdate())for B_time
——————-学生表:Member————————
if exists (select *from sysobjects where name=’Member’)
drop table Member
create table Member
(
MIDChar(10)not null primary key,–学生 ,主键
MNameChar(50)not null–姓名
)
alter table Member
add constraint CK_MID check(len(MID)=12)
——————-课程表———————
if exists (select *from sysobjects where name=’course’)
drop table course
create table course
(
FIDChar(10)not null primary key,–课程,主键
FNameChar(50)not null–课程名
)
—————–成绩表—————————–
if exists (select *from sysobjects where name=’Score’)
drop table Score
create table Score
(
SIDint identity(1,1)not null primary key,–自动编 ,主键,成绩记录
FIDChar(10)references course(FID),–课程 ,外键
MIDChar(10)references Member(MID),–学生 ,外键
Score int not null–成绩
)
————————-测试——————–
insert into student
(stuID,stuName,major)
values(‘201558504131′,’张晴晴’,’计算机’)
insert into book
(BID,title,author)
values(‘201461′,’数据库’,’张大大’)
insert into borrow
(borrowID,stuID,BID,T_time,B_time)
values(‘20148861′,’201558504131′,’201461’,default,default)
??
文章知识点与官方知识档案匹配,可进一步学习相关知识MySQL入门技能树使用数据库创建和删除表31345 人正在系统学习中 相关资源:LibraryO:图书图书馆软件。-开源_图书馆开源项目-其它代码类资源…
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!