view
create view SdeptAge(Sdept,Age)as select Sdept,Avg(Sage)from Student group by Sdept
create view StCInfo(Sname,Ssex,Cname,Grade)as
select Sname,Ssex,Cname,Grade from Student join SC
on Student.Sno=SC.Sno
删除视图
drop view 视图名
删除视图没有影响,删除视图里面的数据就有影响
更新视图
alter view 视图名(基础数据库也会改变)
创建一个CS系 所有成绩均为 优秀的学生视图(学生姓名、年龄、性别、系、平均成绩)
create view CSExSt(Sname,Sage,Ssex,Sdept,AvgGrade) as
select Sname,Sage,Ssex,Sdept,(Select avg(Grade) from SC where Sno=s.Sno) from Student as s
where Sdept='CS' and Sno not in (select Sno from SC where Grade<90) and Sno in (select Sno from SC)
select * from CSExSt
update CSExSt set Sage = Sage - 10 where Sname in (
select top 1 Sname from CSExSt order by AvgGrade Desc)
权限要素
权限授予
权限回收
revoke 操作(列) on 表/视图 from 用户
与with grant option对应:cascade
分级授权
通过视图结合授权来实现
grant select(Sname、Ssex)on Student to U1
grant select on Student to U2
grant insert(Sname、Ssex)on Student to U1 ❌
grant delete,insert on Student to U1
-- delete insert 不能单个授予 但能合起来授予
-- select update 可以
grant select on Course to public
revoke select on Student from U1
create view ISSt as select Sno,Sname from Student where Sdept=‘IS’ with check option
grant select on ISSt
creat view TSInfo(Sno,Sname,Ssex,Sage,Grade,Cname) as
select s.Sno, Sname,Ssex,Sage,Grade,Cname,Tname from Student
as s join on s.Sno=SC.Sno join Course as c on SC.Cno = c.Cno
where Tname = USER
grant select,update on TSInfo to public
DDL 对象 creat alter
DML 操作 select insert update delete
DCL 控制 grant revoke