(1)利用SQL Server Management Studio在teaching数据库中创建表student,表的结构件附件1。
createtable student
(classnochar(20) ,classname varchar(50),departmentchar(20),monitor char(20))
Go
(2)利用Transact-SQL语句在teaching数据库中创建表course、表score、表teacher、表class和表teach_class,各表的结构见附件1。
createtable class
(classnochar(20), classname varchar(50),department char(20),monitor char(20))
Go
Create table student(studentnochar(20),sname char(20),sex char(4),birthday char(20),classno char(15),point char(10),phone char(11),email char(50))
GO
createtable course
(coursenochar(10),cname char(10),type char(8),period char(20),credit char(10))
Go
createtable score
(studentnochar(15),courseno char(10),usually char(15),final char(10))
Go
createtable teacher
(teachernochar(10),tname char(13),major char(20),prof char(40),department char(30))
Go
createtable teach_class
(teachernochar(15),classno char(10),courseno char(15))
Go
(3)用Transact-SQL语句修改表的结构
Ø 为student表增加民族nation列,数据类型为nchar(10),允许为空;
alter table student
addnation nchar(10) null
Ø go
Ø 修改sutdent表中nation列的数据类型为varchar(10);
alter table student
alter column nationvarchar(10) NULL
Ø go
Ø 删除sutdent表中nation列
alter table student
drop column nation
Ø go
(4)利用Transact-SQL语句修改表中的数据
Ø 向student表中插入一条学生记录,(使用自己的学号和相关信息);
insertinto student values('1291410007','谷雨丰','男','9-16','000','100','13361291275','guyf556@gmail.com')
Ø GO
Ø 向score表中插入一条选课记录,(学号使用自己的学号,课程编号为c05109);
insertinto score values('1291410007','c05109','99','99')
Ø GO
Ø 删除上面添加的学生信息和选课信息
Ø delete fromstudent where studentno = '1291410007'
Ø delete fromscore where studentno ='1291410007'
Ø (5)利用SQL Server Management Studio将teaching数据库中score表的courseno列设为引用表course的外键。
Ø
Ø (6)利用Transact-SQL语句将teaching数据库中score表中的studentno列设置为引用表student的外键;将teach_class表中的teacherno、classno和courseno列分别设置为引用表teacher、class和course的外键。
Ø (7)为teaching数据库中class表的classname创建UNIQUE约束,为course表中的cname列和period列的组合创建UNIQUE约束,规定相同学时课程名的唯一性。
Ø (8)利用Transact-SQL语句为teaching数据库中course表的credit列创建CHECK约束,规定学分的取值范围为1—6。
Ø (9)利用Transact-SQL语句为teaching数据库创建规则prof_rule,规定教师职称取值只能为“助教”、“讲师”、“副教授”和“教授”,并将其绑定到teacher表的prof列上;创建默认值对象Email_default,规定电子邮箱地址默认为“无”,并将其绑定到student表的Email列上。
Ø (10)将所给电子表格中的数据导入数据库。
Ø
Ø 附件1
Ø 数据库:teaching
Ø student
字段序号 | 字段名 | 类型 | 取值说明 | 字段含义 |
1 | studentno | nchar(10) | 主键 | 学生学号 |
2 | sname | nchar(8) | 否 | 学生姓名 |
3 | sex | nchar(1) | 否 | 性别 |
4 | birthday | datetime | 否 | 出生日期 |
5 | classno | nchar(6) | 否 | 班级编号 |
6 | point | smallint | 否 | 入学成绩 |
7 | phone | nchar(12) | 否 | 电话 |
8 | | nchar(20) | 否 | 电子信箱 |
Ø course
字段名 | 类型 | 取值说明 | 字段含义 |
courseno | nchar(6) | 主键 | 课程编号 |
cname | nchar(20) | 否 | 课程名称 |
type | nchar(8) | 否 | 类别 |
period | tinyint | 否 | 学时 |
credit | numeric(4,1) | 否 | 学分 |
Ø score
字段名 | 类型 | 取值说明 | 字段含义 |
studentno | nchar(10) | 主键 | 学号 |
courseno | nchar(6) | 课程编号 | |
usually | numeric(6,2) | 否 | 平时成绩 |
final | numeric(6,2) | 否 | 期末成绩 |
Ø teacher
字段名 | 类型 | 取值说明 | 字段含义 |
teacherno | nchar(6) | 主键 | 教师编号 |
tname | nchar(8) | 否 | 教师姓名 |
major | nchar(10) | 否 | 专业 |
prof | nchar(10) | 是 | 职称 |
department | nchar(12) | 否 | 院系部门 |
Ø class
字段名 | 类型 | 取值说明 | 字段含义 |
classno | nchar(6) | 主键 | 班级编号 |
classname | nchar(12) | 否 | 班级名称 |
department | nchar(12) | 否 | 院系部门 |
monitor | nchar(8) | 否 | 联系人 |
Ø teach_class
字段名 | 类型 | 取值说明 | 字段含义 |
teacherno | nchar(6) | 主键 | 教师编号 |
classno | nchar(6) | 班级编号 | |
courseno | nchar(6) | 课程编号 |
Ø
Ø
Ø