CREATE VIEW v_stu_c(`学号`,`姓名`,`课程编号`)
AS
SELECT grade.`学号`,`姓名`,`课程编号`
FROM grade,student_info
WHERE grade.`学号`='0003' AND
grade.`学号`=student_info.`学号`;
CREATE UNIQUE INDEX cno_idx ON curriculum(`课程编号`);
CREATE INDEX grade_idx ON grade(`分数`);
创建视图:
CREATE VIEW v_stu_g(`学号`,`姓名`,`课程名称`,`分数`)
AS
SELECT grade.`学号`,`姓名`,`课程名称`,`分数`
FROM student_info,curriculum,grade
WHERE curriculum.`课程编号`=grade.`课程编号`
AND grade.`学号`=student_info.`学号`;
查询视图:
SELECT `学号`, AVG(`分数`) AS '课程平均分'
FROM v_stu_g
WHERE `学号`='0001';
ALTER VIEW v_stu_g
AS
SELECT `学号`,`姓名`,`性别`
FROM student_info
WITH CHECK OPTION;
6.利用视图v_stu_g为student_info表添加一行数据:学号为0010、姓名为陈婷婷、性别为女。
INSERT INTO v_stu_g
VALUES('0010','陈婷婷','女');
7.利用视图v_stu_g删除学号为0010的学生记录。
DELETE FROM v_stu_g
WHERE `学号`='0010';
8.利用视图v_stu_g修改姓名为张青平的学生的高等数学的分数为87。
UPDATE v_stu_g
SET `分数`='87'
WHERE `课程名称`='高等数学';
9.使用SQL语句删除视图v_stu_c和v_stu_g。
DROP VIEW v_stu_c;
DROP VIEW v_stu_g;
CREATE USER 'st_01'@'localhost'IDENTIFIED by '123456';
GRANT SELECT
on student_info
to 'st_01'@'localhost';
(2)授予用户账号st_01更新家庭住址列的权限。
GRANT UPDATE(`家庭住址`)
on student_info
to 'st_01'@'localhost';
(3)授予用户账号st_01修改表结构的权限。
GRANT ALL
on *
to st_01@localhost;
REVOKE all
on student_info
FROM st_01@localhost;
CREATE role student;
(2)授予角色student查询student_info表的权限。
GRANT SELECT
ON TABLE student_info
to student;
(3)创建本地机用户账号st_02,密码为123。
CREATE USER 'st_02'@'localhost'IDENTIFIED by '123';
(4)授予用户账号st_02角色student的权限。
GRANT student to st_02;
(5)以用户账号st_02连接MySQL服务器,查看student_info表信息。
USE st_02 SELECT *FROM student_info;
(6)撤消用户账号st_02角色student的权限。
REVOKE ON student FROM st_02@localhost;
(7)删除角色student。
drop role 'student';
12.删除用户账号st_01、st_02。
DROP USER 'st_01'@'localhost';
DROP USER 'st_02'@'localhost';