数据库关系代数
基本概念
元祖行:水平方向上每一行为一条记录,这个记录对应1个实体。一般称为元祖,元祖行或者记录
属性列:垂直方向上每一列为一个属性,一般称为属性列,字段等。关系表达式中可以用列序号代替列名
表结构:属性列个数与排列,属性列个数也称为表的目数。
并交叉都是二元运算符
并(∪):综合2个表的所有元组,且去除重复。
交(∩):列出2个表都有的元祖
差(-):以左侧对象为主,在左侧对象的元祖集合中去除右侧对象已有的元祖,则为差
关系s1 | 关系s2 | |||||
sno | sname | sdept | sno | sname | sdept | |
no0001 | mary | is | no0001 | mary | is | |
n00003 | candy | is | no0008 | katter | is | |
no0004 | jam | is | no0021 | tom | is |
s1并s2的结果为
s1∪s2 | ||
sno | sname | sdept |
no0001 | mary | is |
n00003 | candy | is |
no0004 | jam | is |
no0008 | katter | is |
no0021 | tom | is |
s1∩s2
s1∩s2 | ||
sno | sname | sdept |
no0001 | mary | is |
s1-s2
s1-s2 | ||
sno | sname | sdept |
n00003 | candy | is |
no0004 | jam | is |
笛卡尔积():二元运算,属性列是二者之和,元祖行数是二者乘积。元祖结果是以左侧对象的元祖分别拼接右侧对象的元祖,形成不同的排列组合。不同表的同名属性,需要以“表名.列名”加以区分。
s1×s2 | |||||
s1.sno | s1.sname | s1.sdept | s2.sno | s2.sname | s2.sdept |
no0001 | mary | is | no0001 | mary | is |
no0001 | mary | is | no0008 | katter | is |
no0001 | mary | is | no0021 | tom | is |
n00003 | candy | is | no0001 | mary | is |
n00003 | candy | is | no0008 | katter | is |
n00003 | candy | is | no0021 | tom | is |
no0004 | jam | is | no0001 | mary | is |
no0004 | jam | is | no0008 | katter | is |
no0004 | jam | is | no0021 | tom | is |