本篇文章记录了第十二次作业
使用的数据库是SQL Server,使用的数据库管理软件是SQL Server Management Studio.
当然这里是写作业用的全部都是标准SQL。
学生(学号,姓名,年龄,性别,家庭住址,班级号)
班级(班级号,班级名,班主任,班长)
GRANT ALL PRIVILEGES
ON Student,Class
TO U1
WITH GRANT OPTION ;
GRANT SELECT,UPDATE(Adress)
ON Student
TO U2;
GRANT SELECT
ON Class
TO PUBLIC;
GRANT SELECT,UPDATE
ON Student
TO R1;
GRANT R1
TO U1
WITH ADMIN OPTION;
职工(职工号,姓名,年龄,职务,工资,部门号)
部门(部门号,名称,经理名,地址,电话号)
请使用SQL的GRANT和REVOKE语句(加上视图机制)完成一下授权定义或存取控制功能:
GRANT SELECT
ON Employee,Department
TO WangMing;
GRANT INSERT,DELETE
ON Employee,Department
TO LiYong;
GRANT SELECT
ON Employee
WHEN USER()=Ename
TO ALL; /*这里不是很懂,网上搜的*/
这里我本来想建立一个视图就是让用户名和职工名相同的人才能查看到该条记录,但是怎么让用户名能够参与进这个比较中,我不太懂。
GRANT SELECT,UPDATE(Salary)
ON Employee
TO LiuXing;
GRANT ALTER TABLE
ON Employee,Department
TO ZhangXin;
GRANT ALL PRIVILEGES
ON Employee,Department
TO ZhouPing
WITH GRANT OPTION;
CREATE VIEW Dsalary AS
SELECT Dname,MAX(Salary),MIN(Salary),AVG(Salary)
FROM Employee,Department
WHERE Department.dno=Employee.dno
GROUP BY Employee.dno
GRANT SELECT ON Dsalary
TO YangLan;
大部分只要把GRANT改成REVOKE,TO改成FROM就行了
//1
REVOKE SELECT
ON Employee,Department
FROM WangMing;
//2
REVOKE INSERT,DELETE
ON Employee,Department
FROM LiYong;
//3
GRANT SELECT
ON Employee
WHEN USER()=Ename
TO ALL;
//4
REVOKE SELECT,UPDATE(Salary)
ON Employee
FROM LiuXing;
//5
REVOKE ALTER TABLE
ON Employee,Department
FROM ZhangXin;
//6
REVOKE ALL PRIVILEGES
ON Employee,Department
FROM ZhouPing;
//7
REVOKE SELECT
ON Dsalary
FROM YangLan;
DROP VIEW Dsalary;
参考文献:
[1]萨师煊,王珊,数据库系统概论.5版.北京:高等教育出版社,2014.