create database STU_Information
on
(
name=STU_Information, --数据文件逻辑名称
filename='E:\database_STU\STU_Information.mdf',--文件物理存储路径
size=100, --默认以MB为单位,初始大小设置为100MB
maxsize=500, --最大开辟空间500MB
filegrowth=5% --自动增长量5%
)
Log on --创建事务日志文件
(
name=STU_Information_log, --日志文件逻辑名称
filename='E:\database_STU\STU_Information_log.idf',--文件物理存储路径 idf次要|mdf主要
size=10, --默认以MB为单位,初始大小设置为10MB
maxsize=100, --最大开辟空间100MB
filegrowth=5% --自动增长量5%
)
create table Stu --学生表
(
SNo varchar(8) primary key, --主键
SN nvarchar(10),
Sex nchar(2),
ProClass nvarchar(12),
Birthday datetime not null, --不能加(),否则无效
TelNum nvarchar(10) null --不能加(),否则无效
)
create table Course --课程表
(
CNo varchar(8) primary key, --主键
CN nvarchar(10),
Credit float(4),
CHour float(4),
TN nvarchar(10)
)
create table StuWork --学生作业表
(
CNo varchar(8),
SNo varchar(8),
primary key(SNo,CNo),--主键 两列合并
WScore1 float(4),
WScore2 float(4),
WScore3 float(4)
)
alter table StuWork add constraint FK_StuWork_Stu foreign key(SNo) references Stu(SNo); --增加外键
alter table StuWork add constraint FK_ID foreign key(CNo) references Course(CNo);
insert Stu(SNo,SN,Sex,ProClass, Birthday) values('0433','张艳','女','生物04','1986-9-13')
insert into Stu values('0496','李越','男','电子04','1984-2-23','1381290xx')
insert into Stu values('0529','赵欣','男','会计05','1984-1-27','1350222xx')
insert into Stu values('0531','张志国','男','生物05','1986-9-10','1331256xx')
insert into Stu values('0538','于兰兰','女','生物05','1984-2-20','1331200xx')
insert into Stu values('0591','王丽丽','女','电子05','1984-3-20','1332080xx')
insert Stu(SNo,SN,Sex,ProClass, Birthday) values(0592,'王海强','男','电子05','1986-11-1')
insert into Course values ('K001','计算机图形学',2.5,40,'胡晶晶')
insert into Course values ('K002','计算机应用基础',3,48,'任泉')
insert into Course values ('K006','数据结构',4,64,'马跃先')
insert into Course values ('M001','政治经济学',4,64,'孔繁新')
insert into Course values ('S001','高等数学',3,48,'赵晓尘')
insert into StuWork values ('K001','0433',60,75,75)
insert into StuWork values ('K001','0529',70,70,60)
insert into StuWork values ('K001','0531',70,80,80)
insert into StuWork values ('K001','0591',80,90,90)
insert into StuWork values ('K002','0496',80,80,90)
insert into StuWork values ('K002','0529',70,70,85)
insert into StuWork values ('K002','0531',80,80,80)
insert into StuWork values ('K002','0538',65,75,85)
insert into StuWork values ('K002','0592',75,85,85)
insert into StuWork values ('K006','0531',80,80,90)
insert into StuWork values ('K006','0591',80,80,80)
insert into StuWork values ('M001','0496',70,70,80)
insert into StuWork values ('M001','0591',65,75,75)
insert into StuWork values ('S001','0531',80,80,80)
insert StuWork(CNo,SNo,WScore1,WScore3) values ('S001','0538',60,80)
select * from Stu --查询全部学生表信息
select * from Course --查询全部课表信息
select * from StuWOrk --查询全部课表信息
学生表数据
课程表数据
学生作业表数据