博客
关于我
【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/

    你可能感兴趣的文章
    PostgreSQL 10.1 手册_部分 II. SQL 语言_第 15章 并行查询_15.2. 何时会用到并行查询?...
    查看>>
    PostgreSQL 10.1 手册_部分 II. SQL 语言_第 9 章 函数和操作符_9.23. 行和数组比较
    查看>>
    PostgreSQL 10.1 手册_部分 III. 服务器管理_第 21 章 数据库角色
    查看>>
    Postgresql 12.9如何配置允许远程连接
    查看>>
    PostgreSQL 9.6 同步多副本 与 remote_apply事务同步级别 应用场景分析
    查看>>
    Postgresql CopyManager 流式批量数据入库
    查看>>
    PostgreSQL cube 插件 - 多维空间对象
    查看>>
    PostgreSQL Daily Maintenance - cluster table
    查看>>
    PostgreSQL on Linux 最佳部署手册
    查看>>
    PostgreSQL Oracle 兼容性之 - pipelined
    查看>>
    PostgreSQL Point-In-Time Recovery (Incremental Backup)
    查看>>
    postgresql Streaming Replication监控与注意事项
    查看>>
    postgresql 不需要付费_使用数据传输在PostgreSQL执行 外部连接运算符
    查看>>
    postgresql 主从配置_生产环境postgresql主从环境配置
    查看>>
    postgresql 函数&存储过程 ; 递归查询
    查看>>
    PostgreSQL 分组聚合查询中 filter 子句替换 case when
    查看>>
    PostgreSQL 同步流复制锁瓶颈分析
    查看>>
    PostgreSQL 备份与还原命令 pg_dump
    查看>>
    Postgresql 外部表插件postgres_fdw的安装和使用
    查看>>
    PostgreSQL 如何从崩溃状态恢复(上)
    查看>>