2020年-数据库实验详述-BUPT 信通院-- 十安辰

一、实验目的:

  1. 掌握关系数据库的基本知识和概念。
  2. 理解和掌握关系数据库标准SQL语言,能够熟练使用SQL语言完成基本的数据库操作
    和管理任务。
  3. 掌握SSMS数据库管理工具的使用,能够认识并理解基本SQL语句的功能,能够根据
    要求写出基本的数据库操作命令。

二、考察内容:

  1. 使用INSERT、UPDATE、DELETE命令完成记录的插入、修改和删除;
  2. 与索引有关的操作
  3. 简单的SELECT操作;
  4. 关于视图的操作

三、实验详细内容:

1.建立一个数据库,数据库名称为本人学号,其他设置默认。

DROP DATABASE IF EXISTS `2018210000`;
CREATE DATABASE `2018210000`;

2.建立一个学校教学管理数据库,在这个数据库中,存储以下信息:

(1)有关学生的信息,包括学生的学号,姓名,班级,性别,出生时间,政治面貌,籍贯,入学时间,联系电话,简历;
Student(Sno,Sname,Ssex,ClassNo,Sbirth,Status,Hometown,Enrollment,Telephone,Resume)


(2)有关班级的信息,包括班级的班名,专业,年级,人数,班主任;SClass(ClassNo,ClassName,Major,Grade,Number,Advisor)


(3)有关课程的信息,包括课程编号,课程名称,课程类别(是指该课程为必修,指选还是任选),适用专业,适用年级,开课时间(是指在每个学年的第一学期,还是第二学期),学分,周学时;Course(CourseNo,CourseName,Category,Major,Grade,StartTM,Credits,WeekHours)


(4)有关学年课程安排的信息,包括课程编号,开设课程的学年(例如:2019学年),开设课程的班级,任课教师;
Schedule(CourseNo,StartYear,ClassNo,Teacher)


(5)有关学生选课的信息,包括课程编号,学生的学号,成绩;
SC(CourseNo,Sno,Score)

DROP DATABASE IF EXISTS `school`;
CREATE DATABASE `school`;
USE `school`;

DROP TABLE IF EXISTS `course`;
CREATE TABLE `course`  (
  `CourseNo` int(11) NOT NULL COMMENT '课程编号',
  `CourseName` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '课程名称',
  `Category` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '课程类别',
  `Major` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '适用专业',
  `Grade` int(11) NULL DEFAULT NULL COMMENT '适用年级',
  `StartTM` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '开课时间(一二学期)',
  `Credits` int(11) NULL DEFAULT NULL COMMENT '学分',
  `WeekHours` int(11) NULL DEFAULT NULL COMMENT '周学时'
) ENGINE = MyISAM CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC;

DROP TABLE IF EXISTS `sc`;
CREATE TABLE `sc`  (
  `CourseNo` int(11) NOT NULL COMMENT '课程编号',
  `Sno` int(11) NOT NULL COMMENT '学生学号',
  `Score` int(11) NULL DEFAULT NULL COMMENT '成绩'
) ENGINE = MyISAM CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = FIXED;

DROP TABLE IF EXISTS `schedule`;
CREATE TABLE `schedule`  (
  `CourseNo` int(11) NOT NULL COMMENT '课程编号',
  `StartYear` date NULL DEFAULT NULL COMMENT '开设课程的学年,如2019年',
  `ClassNo` int(11) NULL DEFAULT NULL COMMENT '开设课程的班级',
  `Teacher` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '任课教师'
) ENGINE = MyISAM CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC;

DROP TABLE IF EXISTS `sclass`;
CREATE TABLE `sclass`  (
  `ClassNo` int(11) NOT NULL COMMENT '班号',
  `ClassName` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL  COMMENT '班名',
  `Major` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '专业',
  `Grade` int(11) NULL DEFAULT NULL COMMENT '年级',
  `Number` int(11) NULL DEFAULT NULL COMMENT '人数',
  `Advisor` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '班主任' 
) ENGINE = MyISAM CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC;

DROP TABLE IF EXISTS `student`;
CREATE TABLE `student`  (
  `Sno` int(11) NOT NULL COMMENT '学号',
  `Sname` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '姓名',
  `Ssex` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '性别',
  `Classno` int(11) NULL DEFAULT NULL COMMENT '班级号',
  `Sbirth` date NULL DEFAULT NULL COMMENT '出生日期',
  `Status` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '政治面貌',
  `Hometown` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '籍贯',
  `Enrollment` date NULL DEFAULT NULL COMMENT '入学时间',
  `Telephone` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '联系电话',
  `Resume` varchar(255) CHARACTER SET utf8 NULL COMMENT '简历'
) ENGINE = MyISAM CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC;

3.在student表中插入数据(‘姓名:张三’,‘性别:男’,‘生日:1997-04-05’,‘学号:201815126’,‘班级:2018123’,‘政治面貌:团员’,‘入学时间2018-09-01’,‘电话:13812345678’,‘籍贯:北京’)

INSERT INTO `student` VALUES 
(201815126, '张三', '男', 2018123, '1997-04-05', '团员', '北京', '2018-09-01', '13812345678', NULL);

4.在course表中插入数据(‘1’,‘数据库技术’,‘指选’,‘通信工程’,‘第2学期’,2,2)

INSERT INTO `course` VALUES (1, '数据库技术', '指选', '通信工程', '2', '第二学期', 2, 2);

5.在SC表中插入数据(‘学号:201815126’,‘课程编号:1’)

INSERT INTO `sc` VALUES (1, 201815126, NULL);

6.在course表中将课程号为1的课程的开课时间改为“每年第二学期”

UPDATE `course` SET `StartTM` = '每年第二学期' WHERE `CourseNo` = 1;

7.在SC表中将学号为201815126且课程号为1的成绩设置为90

UPDATE `SC` SET `Score` = 90 WHERE `Sno` = 201815126 AND `CourseNo` = 1;

8.在SC表中将学号为201815126且课程号为1的数据删除

DELETE FROM `SC` WHERE `Sno` = 201815126 AND `CourseNo` = 1;

9.使用truncate命令删除表SC中的数据

TRUNCATE TABLE `SC`;

10.将student表中的学号、姓名、班级保存到一个新建的表中,新建的表名称为stu

DROP DATABASE IF EXISTS stu;
CREATE TABLE stu SELECT * FROM `student`;

11.对上述各个表施加自定义的完整性约束,并向每个表中添加三条自定义的数据

为了后续方便操作便利,插入更多数据

-- 对course表
ALTER TABLE course ADD PRIMARY KEY(`CourseNo`);
INSERT INTO `school`.`course`(`CourseNo`, `CourseName`, `Category`, `Major`, `Grade`, `StartTM`, `Credits`, `WeekHours`) VALUES (2, 'C++程序设计', '必修', '信息工程', 1, '每年第一学期', 3, 3);
INSERT INTO `school`.`course`(`CourseNo`, `CourseName`, `Category`, `Major`, `Grade`, `StartTM`, `Credits`, `WeekHours`) VALUES (3, '区块链导论', '任选', '计算机', 1, '每年第二学期', 2, 2);
INSERT INTO `school`.`course`(`CourseNo`, `CourseName`, `Category`, `Major`, `Grade`, `StartTM`, `Credits`, `WeekHours`) VALUES (4, 'python程序设计', '指选', '电子信息工程', 1, '每年第二学期', 2, 2);
INSERT INTO `school`.`course`(`CourseNo`, `CourseName`, `Category`, `Major`, `Grade`, `StartTM`, `Credits`, `WeekHours`) VALUES (5, 'java程序设计', '指选', '信息工程', 1, '每年第一学期', 2, 2);
INSERT INTO `school`.`course`(`CourseNo`, `CourseName`, `Category`, `Major`, `Grade`, `StartTM`, `Credits`, `WeekHours`) VALUES (6, 'c程序设计', '指选', '通信工程', 1, '每年第一学期', 2, 2);

-- 对sclass表
ALTER TABLE sclass ADD PRIMARY KEY(`ClassNo`);
INSERT INTO `school`.`sclass`(`ClassNo`, `ClassName`, `Major`, `Grade`, `Number`, `Advisor`) VALUES (2018123, '一班', '通信工程', 2, 27, '史珍香');
INSERT INTO `school`.`sclass`(`ClassNo`, `ClassName`, `Major`, `Grade`, `Number`, `Advisor`) VALUES (2018456, '二班', '信息工程', 2, 28, '姬从良');
INSERT INTO `school`.`sclass`(`ClassNo`, `ClassName`, `Major`, `Grade`, `Number`, `Advisor`) VALUES (2018789, '三班', '电子信息工程', 2, 29, '庞光');
INSERT INTO `school`.`sclass`(`ClassNo`, `ClassName`, `Major`, `Grade`, `Number`, `Advisor`) VALUES (2017211113, '四班', '信息工程', 3, 29, '艾骤');

-- 对student表
ALTER TABLE student ADD PRIMARY KEY(Sno);
ALTER TABLE student ADD CONSTRAINT fk_student_sclass FOREIGN KEY(ClassNo) REFERENCES sclass(ClassNo);
INSERT INTO `school`.`student`(`Sno`, `Sname`, `Ssex`, `ClassNo`, `Sbirth`, `Status`, `Hometown`, `Enrollment`, `Telephone`, `Resume`) VALUES (201815226, '李四', '男', 2018456, '2000-04-05', '团员', '天津', '2018-08-01', '15812345678', NULL);
INSERT INTO `school`.`student`(`Sno`, `Sname`, `Ssex`, `ClassNo`, `Sbirth`, `Status`, `Hometown`, `Enrollment`, `Telephone`, `Resume`) VALUES (201815326, '王二麻子', '男', 2018789, '1997-08-28', '团员', '上海', '2018-09-01', '17812345678', NULL);
INSERT INTO `school`.`student`(`Sno`, `Sname`, `Ssex`, `ClassNo`, `Sbirth`, `Status`, `Hometown`, `Enrollment`, `Telephone`, `Resume`) VALUES (201815426, '魏生津', '女', 2018123, '2000-09-11', '团员', '深圳', '2018-09-01', '19812345678', NULL);
INSERT INTO `school`.`student`(`Sno`, `Sname`, `Ssex`, `ClassNo`, `Sbirth`, `Status`, `Hometown`, `Enrollment`, `Telephone`, `Resume`) VALUES (201815526, '范统', '男', 2018789, '1997-09-11', '团员', '上海', '2018-09-01', '19812345678', NULL);
INSERT INTO `school`.`student`(`Sno`, `Sname`, `Ssex`, `ClassNo`, `Sbirth`, `Status`, `Hometown`, `Enrollment`, `Telephone`, `Resume`) VALUES (201815626, '辣鸡小新', '女', 2018789, '1995-09-11', '团员', '深圳', '2018-09-01', '19812345678', NULL);
INSERT INTO `school`.`student`(`Sno`, `Sname`, `Ssex`, `ClassNo`, `Sbirth`, `Status`, `Hometown`, `Enrollment`, `Telephone`, `Resume`) VALUES (201815726, '沈京兵', '女', 2018456, '1990-09-11', '团员', '北京', '2018-09-01', '19812345678', NULL);
INSERT INTO `school`.`student`(`Sno`, `Sname`, `Ssex`, `ClassNo`, `Sbirth`, `Status`, `Hometown`, `Enrollment`, `Telephone`, `Resume`) VALUES (201815826, '王小明', '男', 2018123, '2001-09-11', '团员', '天津', '2018-09-01', '19812345678', NULL);
INSERT INTO `school`.`student`(`Sno`, `Sname`, `Ssex`, `ClassNo`, `Sbirth`, `Status`, `Hometown`, `Enrollment`, `Telephone`, `Resume`) VALUES (201815926, '王小红', '女', 2018123, '2001-05-11', '团员', '山东', '2018-09-01', '19812345678', NULL);
INSERT INTO `school`.`student`(`Sno`, `Sname`, `Ssex`, `ClassNo`, `Sbirth`, `Status`, `Hometown`, `Enrollment`, `Telephone`, `Resume`) VALUES (201815026, '王小绿', '女', 2017211113, '1995-06-11', '团员', '山东', '2018-09-01', '19812345678', NULL);
INSERT INTO `school`.`student`(`Sno`, `Sname`, `Ssex`, `ClassNo`, `Sbirth`, `Status`, `Hometown`, `Enrollment`, `Telephone`, `Resume`) VALUES (201815016, '王小黄', '男', 2017211113, '1996-07-11', '团员', '山东', '2018-02-01', '19812345678', NULL);
-- 对sc表
ALTER TABLE sc ADD CONSTRAINT fk_sc_course FOREIGN KEY(CourseNo) REFERENCES course(CourseNo);
ALTER TABLE sc ADD CONSTRAINT fk_sc_student FOREIGN KEY(Sno) REFERENCES student(Sno) ON DELETE CASCADE;
INSERT INTO sc VALUES(1,201815126,99);
INSERT INTO sc VALUES(2,201815226,77);
INSERT INTO sc VALUES(3,201815326,66);
INSERT INTO sc VALUES(4,201815126,69);
INSERT INTO sc VALUES(6,201815526,80);
INSERT INTO sc VALUES(5,201815626,NULL);
INSERT INTO sc VALUES(4,201815726,NULL);
INSERT INTO sc VALUES(6,201815826,55);
INSERT INTO sc VALUES(6,201815026,56);
INSERT INTO sc VALUES(5,201815026,94);
INSERT INTO sc VALUES(2,201815026,85);
INSERT INTO sc VALUES(6,201815016,95);
INSERT INTO sc VALUES(1,201815926,59);

-- 对schedule表
ALTER TABLE `schedule` ADD PRIMARY KEY(CourseNo,ClassNo);
ALTER TABLE `schedule` ADD CONSTRAINT fk_schedule_course FOREIGN KEY(CourseNo) REFERENCES course(CourseNo);
ALTER TABLE `schedule` ADD CONSTRAINT fk_schedule_sclass FOREIGN KEY(ClassNo) REFERENCES sclass(ClassNo) ;
INSERT INTO `school`.`schedule`(`CourseNo`, `StartYear`, `ClassNo`, `Teacher`) VALUES (1, '2019学年', 2018123, '梦梵');
INSERT INTO `school`.`schedule`(`CourseNo`, `StartYear`, `ClassNo`, `Teacher`) VALUES (2, '2019学年', 2018456, '姬从良');
INSERT INTO `school`.`schedule`(`CourseNo`, `StartYear`, `ClassNo`, `Teacher`) VALUES (3, '2020学年', 2018789, '杜子腾');
INSERT INTO `school`.`schedule`(`CourseNo`, `StartYear`, `ClassNo`, `Teacher`) VALUES (4, '2020学年', 2018123, '马分');
INSERT INTO `school`.`schedule`(`CourseNo`, `StartYear`, `ClassNo`, `Teacher`) VALUES (5, '2020学年', 2018456, '夏琉');
INSERT INTO `school`.`schedule`(`CourseNo`, `StartYear`, `ClassNo`, `Teacher`) VALUES (6, '2020学年', 2018789, '李建仁');

12.查询全部学生的姓名、性别、籍贯和出生日期

SELECT Sname AS '姓名',Ssex AS '性别',Hometown AS '籍贯',Sbirth AS '出生日期'
FROM student;

查询结果如下:

13.查询全部学生的姓名、性别和年龄

SELECT Sname AS '姓名',Ssex AS '性别',FLOOR(DATEDIFF(CURDATE(),student.Sbirth)/365.2422) AS '年龄'
FROM student;

14.查询姓“王”的所有学生的姓名和年龄

SELECT Sname AS '姓名',FLOOR(DATEDIFF(CURDATE(),student.Sbirth)/365.2422) AS '年龄'
FROM student
WHERE Sname LIKE '王%';

15.查询选修了课程号为1或2课程,且成绩高于或等于70分的学生的姓名,课程名和成绩

SELECT student.Sname AS'姓名',course.CourseName AS'课程名',sc.Score AS'成绩'
FROM student,course,sc
WHERE student.Sno= sc.Sno 
			AND course.CourseNo = sc.CourseNo 
			AND sc.Score >=70 
			AND sc.CourseNo IN (1,2);

16.查询没有考试成绩的学生姓名和课程名

SELECT student.Sname  '姓名',course.CourseName  '课程名'
FROM student,course,sc
WHERE student.Sno = sc.Sno
			AND course.CourseNo = sc.CourseNo
			AND sc.Score IS NULL;

17.查询年龄大于女同学平均年龄的男学生姓名和年龄

SELECT student.Sname AS '姓名',FLOOR(DATEDIFF(CURDATE(),student.Sbirth)/365.2422) AS '年龄'
FROM student
WHERE student.Ssex = '男' 
			AND FLOOR(DATEDIFF(CURDATE(),student.Sbirth)/365.2422) >= (
			SELECT AVG(FLOOR(DATEDIFF(CURDATE(),student.Sbirth)/365.2422))
			FROM student
			WHERE student.Ssex = '女'
			);

18.按照学号分组统计每个同学的选课数量,要求显示姓名和选课数量

SELECT student.Sname '姓名',
			(Select Count(sc.Sno) From sc  Where sc.Sno=student.Sno) '选课数量'
FROM student
GROUP BY student.Sno;

19.查询所选课程平均成绩在60分以上同学的选课数量,要求显示姓名和选课数量

Select student.Sname '姓名',
			(Select Count(sc.Sno) From sc  Where sc.Sno=student.Sno) '选课数量'
From student,sc
Group By student.Sno
Having Avg(Score)>60

20.查询王小明同学的老乡(籍贯相同的学生)的学号和性别

SELECT student.Sno '学号',student.Ssex '性别' 
FROM student
WHERE student.Hometown =(
			SELECT Hometown FROM student WHERE student.Sname = '王小明'
)

21.查询班主任 和学生某一门所选课程任课教师相同 的学生的姓名和出生日期

SELECT student.Sname '姓名',
			 student.Sbirth '出生日期'
FROM student,sc,sclass,schedule
WHERE student.ClassNo = sclass.ClassNo
			AND sc.CourseNo = `schedule`.CourseNo
			AND sc.Sno=student.Sno
			AND sclass.Advisor = schedule.Teacher


22.查询王小明同学的政治面貌、班级名称和所选课程

SELECT student.`Status` '政治面貌',sclass.ClassName '班级名称',course.CourseName 
FROM student,sclass,course,sc
WHERE student.Sname = '王小明'
			AND student.ClassNo = sclass.ClassNo
			AND student.Sno = sc.Sno
			AND course.CourseNo = sc.CourseNo

23.创建一个选课数量统计表并将姓名和该同学的选课数量插入到表中

DROP TABLE IF EXISTS select_course;
CREATE TABLE select_course
SELECT student.Sname,(Select Count(sc.Sno) From sc  Where sc.Sno=student.Sno) 'Scourse' 
FROM student,sc
WHERE student.Sno = sc.Sno
GROUP BY student.Sno;

24.将籍贯是山东的学生插入到新的 stuShandong表中

DROP TABLE IF EXISTS stuShandong;
CREATE TABLE stuShandong
SELECT * 
FROM student
WHERE student.Hometown = '山东';

25.将班级为2017211113的所有学生所选课程的成绩加一分

UPDATE sc
SET Score = Score + 1
WHERE sc.Sno IN (
			SELECT student.Sno
			FROM student
			WHERE student.ClassNo = 2017211113);




26.在完整性约束的条件下从整个数据库中删除关于王小明同学的全部信息

# 利用11题添加的级联删除外键直接删除学生表中王小明的记录即可
DELETE  FROM student WHERE student.Sname = '王小明';

27.在学生信息表的学生姓名字段上创建唯一索引

CREATE UNIQUE INDEX name_index ON student(Sname);

28.修改上述索引的索引名称

#按照《数据库系统概论》一书中提供的方法,修改语句为
-- ALTER INDEX name_index RENAME TO Stu_name;
#mysql没有提供修改索引的方法,需要删除索引再重新创建
ALTER TABLE student
DROP INDEX name_index;
CREATE UNIQUE INDEX Stu_name ON student(Sname);

29.在选课信息表中按学号+课程编号建立主键索引,索引组织方式为聚簇索引

# 按照《数据库系统概论》一书中提供的方法,创建聚簇索引的语句为
-- CREATE CLUSTER INDEX sc_index ON sc(Sno,CourseNo);
# mysql的聚簇索引是bai指innodb引擎的特性
# MYSQL中没有CLUSTER索引的概念,只有INNODB的主键是使用CLUSTER方式存储的,直接添加学号与课程号为选课信息表的主键即可
ALTER TABLE sc ADD PRIMARY KEY(Sno,CourseNo);

30.删除上一步中创建的索引

# 先删除外键约束,否则无法删除主键
ALTER TABLE sc DROP FOREIGN KEY fk_sc_course;
ALTER TABLE sc DROP FOREIGN KEY fk_sc_student;
ALTER TABLE sc DROP PRIMARY KEY ;
SHOW INDEX FROM sc;

31.创建视图,包含所有通信工程专业的学生的信息

# 通信工程专业的班级是2018123班,选出班级为2018123的学生即可
CREATE VIEW stu_tongxin 
AS
SELECT * 
FROM student
WHERE student.ClassNo = 2018123;

32.创建视图,包含所有学生的学号,姓名,选课的课程名和成绩

DROP VIEW IF EXISTS stu_info;
CREATE VIEW stu_info
AS
SELECT student.Sno 'Sno', student.Sname 'Sname', course.CourseName 'CourseName', sc.Score 'Score'
FROM student,sc,course
WHERE student.Sno = sc.Sno
			AND course.CourseNo = sc.CourseNo

33.创建视图,包含所有课程的课程号,课程名,班级名称及每班选课的人数

DROP VIEW IF EXISTS course_info;
CREATE VIEW course_info
AS
SELECT course.CourseNo 'CourseNo', course.CourseName 'CourseName', sclass.ClassName 'ClassName', num
FROM course,sclass,
		(SELECT course.CourseNo 'CourseNo',student.ClassNo 'ClassNo', count(*) AS num 
		FROM course,student,sc
		WHERE course.CourseNo = sc.CourseNo
					AND student.Sno = sc.Sno
		GROUP BY course.CourseNo,student.ClassNo) tmp
WHERE course.CourseNo = tmp.CourseNo
			AND sclass.ClassNo = tmp.ClassNo;

34.修改题目31中的视图,包括with check option选项

ALTER VIEW stu_tongxin 
AS
SELECT * 
FROM student
WHERE student.ClassNo = 2018123
WITH CHECK OPTION;

35.修改题目32中的视图,包括with encryption选项

# 以下语句会报错,原因是mysql并不支持视图加密
DROP VIEW IF EXISTS stu_info;
ALTER VIEW stu_info
AS
SELECT student.Sno 'Sno', student.Sname 'Sname', course.CourseName 'CourseName', sc.Score 'Score'
FROM student,sc,course
WHERE student.Sno = sc.Sno
			AND course.CourseNo = sc.CourseNo
with encryption;

36.在题目31创建的视图中查询所有2000年以后出生的学生的姓名和性别

SELECT stu_tongxin.Sname '姓名', stu_tongxin.Ssex '性别'
FROM stu_tongxin
WHERE year(stu_tongxin.Sbirth) >= 2000;

37.在题目32创建的视图中插入一条自定义数据

# 由于stu_info是由多张表组成的视图,mysql是无法间接插入数据的,原因是视图中并没有实体表中的全部字段(即建表的字段),故会报错。
INSERT INTO `school`.`stu_info`(`Sno`, `Sname`, `CourseName`, `Score`) VALUES (201815223, '黄龙', 'go程序设计', 99);

38.删除题目33中创建的视图

DROP VIEW course_info;
展开阅读全文
©️2020 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值