数据库系统概念第六版 第四章练习题 12 14 18

数据库系统概念第六版 第四章练习题 12 14 18

4.12

对于图中的数据库,写出一个查询来找到那些没有经理的雇员。注意一个雇员可能只是没有列出其经理或者可能有null经理。使用外连接书写查询,然后不用外连接再重写查询。

--外连接版本
select employee_name
from employee natural left outer join manages
where manager_name is NULL;
--使用左外连接后,仅在employee中出现而在manages不出现的employee_name对应的manage_name也会为null

--非外连接版本
--exists版本:
select employee_name
from employee as e
where not exists
(select employee_name
from manages as m
where e.employee_name = m.employee name and
m.manager_name is not null);

--in版本:
select employee_name
from employee 
where employee_name not in
(select employee_name
from manages 
manager_name is not null);
--首先筛选出有经理的employee_name,然后不在该范围的employee就是所求
4.14

给定学生每年修到的学分数,如何定义视图tot_credits(year,num_credits)

(这个题目我起初有些不懂,看了英文pdf中的描述就懂了。中文翻译的顺序颠倒了:)

Show how to define a view tot_credits(year,num_credits),giving the total number of credits taken by students in each years.

create view tot_credits(year,num_credits)
as 
(select year,sum(credits)
from takes natural join course
group by year)
4.18

假定用户A拥有关系上的所有权限,该用户把关系R上的查询权限以及授予该权限的权限授予给了public。假定用户B将r上的查询权限授予A,这是否导致授权图中的环?解释原因

答:会引起一个授权图的环。A对public授予了查询权限和授予权限的权限,然后public会和系统中所有的用户都建立一个授权路径用于授权,故B会获得查询权限和授予权限的权限。因此此时B就可以将查询权限授予给A,故现在的授权图有了一个环,即 A->public->B->A.

发布了68 篇原创文章 · 获赞 36 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/dingdingdodo/article/details/100937270
今日推荐