- 行 row / 元组 tuple / 记录 record
- 列 column / 字段 field / 属性 attribute / 数据项 dataitem
DBMS(DataBase Management System)
三个层次:
- External Level (User Level / View Level)
局部:用户能看到的“部分” - Conceptual Level (Logical Level)
全局:管理数据,与关联约束 - Internal Level (Physical Level)
存储介质,索引等
三级模式,两层映像
关系模型
- 基本结构 -> Table Relation : 一个Relation就是一个Table
- 基本操作 -> Relation Calculation : Table间的运算
- 完整性约束 -> Constraints about Table : 完整性约束
数据(Data) / 视图(View) --> 模式(Schema) / 表 (Table) --> 模型 (Model) / 关系模型 (Relational Model)
Schema == Table Head
域(Domain): 列属性
Relation的特性:
- 列同质(同数据类型,同Domain)
- 不同列可以来自同一个Domain
- 行列无序
- Relation中要去重(以元组为单位),Table中可重复
- 满足Relation的第一范式(1NF,属性不可再分:复合属性,多值属性)
几种码、键
超码 (Super Key) --> 候选码 (Canditate Key) --> 主键 (Primary Key) <-- 外码(Foreign Key)
- 超码 (Super Key):Table中一组能够区分开不同Tuple的Attributes集合
- 候选码(Canditate Key): 最小超码(类似最小连通分量,这个集合的Attributes再少就不能唯一标识Tuple了)
- 主码(Primary Key): 用户自己选取一个Canditate Key做Primary Key,下划线标识
- 外码(Foreign Key): “链接”到其他table主码的一组Attributes --> referencing
- 全码(All Key): 由所有属性构成Canditate Key
参照关系&被参照关系:外码所在的Relation(table)叫做参照关系(Referencing Relation),是主动的一方;主码所在的Relation叫做被参照关系(Referenced Relation)
完整性约束
- 实体完整性:主码值不能为null
- 参照完整性:外码只能取被参照关系主码中存在的值 或 取null (新来的)
- 用户自定义完整性:Check
关系代数
- 广义投影:投影列表中使用算数函数(聚集函数),必须将结果Rename
扩展操作
- 交 (Intersection): Difference
- θ-连接(Theta-Join): Product + Project
等值连接(Equal-Join)
自然连接(Natural-Join):只连接有相同(Attribute : Value)的tuple
外连接(Outer-Join):Left-Outer-Join / Right-Outer-Join / Full-Outer-Join
一般顺序:联选投: Join -> Select -> Project
- 除(Division):
注意:R ÷ S: S的属性必须是R的真子集
应用于:求全部的 / 所有的…的问题
关系运算的优先级
Project > Select > Product > Join = Division > Intersection > Union = Difference
关系演算
元组演算 / 域演算