核心!DB关系代数理论分析和用SQL语句实现
关系代数6种常见的基本操作:
select: σ
∧ and 、∨ or、┐not
举个例子:
用 选择下表记录:
选择结果如下:
SQL语句实现方法:
select A,B,C,D from r where A=B and D>5;
project(投影): ∏
注:Duplicate rows removed from result, since relations are sets集合
举个例子:
用投影下表:
投影结果如下(要去除重复):
用SQL语句实现此功能:
select A,C from r;
union : ∪
two tables must have the same arity 参数数量
The attribute domains must be compatible能共处的 [kəm'pætəbl]
to find all courses taught in the Fall 2009 semester, or in the Spring 2010 semester, or in both
举个例子:
用实现下表合并:
结果如下:
用SQL语句实现此功能:
(select A,B from r)union (select A,B from s);
set difference : -
举个例子:
用操作下表:
结果如下:
(select A,B from r) except (select A,B from s);
Cartesian product: x
Assume that attributes of two tables are disjoint不相交的
If attributes of r and s are not disjoint, then renaming must be used.
用操作下表:
结果如下:
用SQL语句实现如下:
select * from r,s;
rename : p
Additional operators:
Set intersection
Natural join
Assignment
Outer Join
Extended relational algebra operatiors:
Generalized Projection
Aggregate Functions