3.18 列出两个原因,说明为什么空值可能被引入到数据库中。
1. 非主码属性在没有非空的限制的情况下,被插入了空值。
2. 外码完整性约束中有一项是on delete set null,当外码的元组被删除时,所依赖的关系元组属性也会被置空。
3. 19 证明在SQL中,<>all等价于not in。
可能不够严谨的做法,做个练习也许就能证明。查找所有工资不等于Biology系工资的教师。
select name, salary from instructor
where salary not in (select salary from instructor
where dept_name = 'Biology');
select name, salary from instructor
where salary <>all (select salary from instructor
where dept_name = 'Biology');
结果都一样:
name | salary
------------+-----------
Wu | 90000.00
Mozart | 40000.00
Einstein | 95000.00
El Said | 60000.00
Gold | 87000.00
Califieri | 62000.00
Singh | 80000.00
Kim | 80000.00
Srinivasan | 71500.00
Katz | 82500.00
Brandt | 101200.00
(11 rows)
3.20 给出图3-20中雇员数据库的SQL模式定义。为每个属性选择合适的域,并为每个关系模式选择合适的主码。
请参考练习3.9