博客
关于我
【2020-2021春学期】数据库作业11:第四章课后题
阅读量:136 次
发布时间:2019-02-27

本文共 1127 字,大约阅读时间需要 3 分钟。

建立两个表,并为六个用户授予相应权限

首先创建以下两个表:

create table staff(Sno char, Sname char, Sage int, Sduty char, Ssalary int, Sdept char);

create table dept(Dno char, Dname char, Dboss char, Daddress char, Dphone char);

创建六个用户:王明、李勇、刘星、张新、周平、杨兰,均为无登录用户。

用户权限分配方案如下:

  • 王明获得两个表的SELECT权限:

    grant select on staff to 王明;
    grant select on dept to 王明;

  • 李勇获得两个表的INSERT和DELETE权限:

    grant insert, delete on staff to 李勇;
    grant insert, delete on dept to 李勇;

  • 每个职工仅对其自身记录拥有SELECT权限:

    grant select on staff when user() = Nameto all;
    grant select on dept when user() = Nameto all;

  • 刘星获得职工表的SELECT和更新(工资字段)权限:

    grant select, update(Ssalary) on staff to 刘星;

  • 张新获得两个表的更新权限:

    grant update on staff to 张新;
    grant update on dept to 张新;

  • 周平获得两个表的全部权限(SELECT、INSERT、UPDATE、DELETE),并可授予其他用户权限:

    grant all on staff to 周平 with grant option;
    grant all on dept to 周平 with grant option;

  • 杨兰获得每个部门的SELECT最高工资、最低工资和平均工资权限,但不得查看个人工资:

    -- 需要先创建视图:
    create view view_salary as
    select staff.Sdept department_number,
    max(staff.Ssalary) highest_salary,
    min(staff.Ssalary) lowest_salary,
    avg(staff.Ssalary) average_salary
    from staff
    group by staff.Sdept;
    grant select on view_salary to 杨兰;

  • 注:聚合函数列名需明确指定。

    转载地址:http://cknb.baihongyu.com/

    你可能感兴趣的文章
    python网络爬虫(2)——scrapy框架的基础使用
    查看>>
    python网络爬虫实例教程试读_Python网络爬虫实战教程(全套完整版) - 学途无忧网 - 做技术的王者 - Powered By EduSoho...
    查看>>
    Python 使用哈希函数用于加密
    查看>>
    Python 依赖管理的革新——Poetry 深度解析
    查看>>
    python 保留精度及增加去除数字的千位分隔符(金额化数字)
    查看>>
    python 倒计时 9,8,7,。。。。。。0
    查看>>
    Python 入门开发学习笔记之数据的增删改查
    查看>>
    Python 入门教程(2)搭建环境 2.4、VSCode配置Node.js运行环境
    查看>>
    Python 八大排序算法合集
    查看>>
    python 关于epoll的学习
    查看>>
    Python 内存管理
    查看>>
    Python 内嵌函数:它们有什么用处?
    查看>>
    Python 内置 sum 函数 vs. for 循环性能
    查看>>
    Python 内置时间模块
    查看>>
    python 内部如何实现命名元组?
    查看>>
    python 写入json数据到数据库
    查看>>
    Python 列表删除相同的元素
    查看>>
    Python 初学者需要知道的四条建议
    查看>>
    Python 判断字符串是否包含子字符串
    查看>>
    python 判断当前时间是否为零点
    查看>>