第四章作业
文章目錄
- 學生 班級模式
- 職工 部門模式
- 撤回權(quán)限
- 總結(jié)
學生 班級模式
先建立兩個模式
學生(學號,姓名,年齡,性別,家庭住址,班級號)
班級(班級號,班級名,班主任,班長)
create table Class(Cno int primary key,Cname char(10) not null,Chead char(5) not null,Cmonitor char(5) not null); create table Student(Sno char(15) primary key,Sname char(5) not null,Sage smallint,Ssex char(2) check(Ssex in('男','女')), Saddress char(50),Sclass intforeign key(Sclass) references Class(Cno));.
新建用戶U1,U2和角色R1,可以直接右鍵建立也可以用SQL語句,不在細說
(1)授予用戶U1對兩個表的所有權(quán)限,并可給其他用戶授權(quán)。
grant all privileges on Class to U1 with grant option; grant all privileges on Student to U1 with grant option;
(2)授予用戶U2對學生表具有查看權(quán)限,對家庭住址具有更新權(quán)限。
(3)將對班級表查看權(quán)限授予所有用戶。
grant select on Class to public(4)將對學生表的查詢、更新權(quán)限授予角色R1。
grant select,update on Student to R1;
(5)將角色RI授予用戶U1,并且U1可繼續(xù)授權(quán)給其他角色。
執(zhí)行完語句之后可以雙擊用戶查看
安全對象中可以查看對那些表有哪些權(quán)限,成員身份中可以找到角色成員
下方可以查看權(quán)限
職工 部門模式
先建立兩個模式
職工(職工號,姓名,年齡,職務,工資,部門號)
部門(部門號,名稱,經(jīng)理名,地址,電話號)
create table Department(Dno int primary key,Dname char(5),Dmanager char(5),Daddress char(5),Dphone char(11)); create table Employee(Eno char(20) primary key,Ename char(2) not null,Eage int,Ework char(10),Esalary int,Edep int foreign key(Edep) references Department(Dno));(1)用戶王明對兩個表有SELECT權(quán)限。
grant select on Employee to 王明; grant select on Department to 王明;(2)用戶李勇對兩個表有INSERT和DELETE權(quán)限。
grant insert,delete on Employee to 李勇; grant insert,delete on Department to 李勇;(3)每個職工只對自己的記錄有SELECT權(quán)限。
grant select to Empolyee when user()=name to all --標準SQLcreate view new1 as select * from Employee where Employee.Ename = user --分開執(zhí)行 grant select on new1 to public; --TSQL
(4)用戶劉星對職工表有SELECT權(quán)限,對工資字段具有更新權(quán)限。
(5)用戶張新具有修改這兩個表的結(jié)構(gòu)的權(quán)限。
grant alter on Employee to 張新 grant alter on Department to 張新(6)用戶周平具有對兩個表的所有權(quán)限(讀、插、改、刪數(shù)據(jù)),并具有給其他用戶授權(quán)的權(quán)限。
grant select,insert,update,delete on Employee to 周平 with grant option grant select,insert,update,delete on Department to 周平 with grant option(7)用戶楊蘭具有從每個部門職工中SELECT最高工資、最低工資、平均工資的權(quán)限,他不能查看每個人的工資。
create view salary(dep,ma,mi,av) as select Edep,max(Esalary),min(Esalary),avg(Esalary) from Employee group by Employee.Edep; --分開執(zhí)行 grant select on salary to 楊蘭;撤回權(quán)限
(1)
revoke select on Department from 王明; revoke select on Employee from 王明(2)
revoke insert,delete on Department from 李勇; revoke insert,delete on Employee from 李勇;(3)
revoke select on new1 from public; drop view new1; --或者直接刪除視圖 drop view new1;(4)
revoke select,update(Salary) on Employee from 劉星;(5)
revoke alter on Employee from 張新; revoke alter on Department from 張新;(6)
revoke select,update,delete,insert on Employee from 周平; revoke select,update,delete,insert on Department from 周平;(7)
revoke select on salary from 楊蘭; drop view salary; --或者直接刪除視圖 drop view salary;總結(jié)
本章作業(yè)主要是權(quán)限的授權(quán)和收回,通過習題對用戶和角色的關(guān)系有了更深一步的認識,角色可以直接作為用戶的成員。另外,也了解到,為了更好的實現(xiàn)權(quán)限分配和數(shù)據(jù)保密,可以建立視圖。如職工只能查看自己記錄,設(shè)置只能查看部門的最高工資等,只要設(shè)立視圖,然后只把對視圖的相關(guān)權(quán)限授予用戶。
總結(jié)
- 上一篇: Mac上IntelliJ IDEA设置类
- 下一篇: 类加载时机