数据库:关系模型

  • 行 row / 元组 tuple / 记录 record
  • 列 column / 字段 field / 属性 attribute / 数据项 dataitem

DBMS(DataBase Management System)
三个层次:

  1. External Level (User Level / View Level)
    局部:用户能看到的“部分”
  2. Conceptual Level (Logical Level)
    全局:管理数据,与关联约束
  3. 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的特性:

  1. 列同质(同数据类型,同Domain)
  2. 不同列可以来自同一个Domain
  3. 行列无序
  4. Relation中要去重(以元组为单位),Table中可重复
  5. 满足Relation的第一范式(1NF,属性不可再分:复合属性,多值属性)

几种码、键

超码 (Super Key) --> 候选码 (Canditate Key) --> 主键 (Primary Key) <-- 外码(Foreign Key)

  1. 超码 (Super Key):Table中一组能够区分开不同Tuple的Attributes集合
  2. 候选码(Canditate Key): 最小超码(类似最小连通分量,这个集合的Attributes再少就不能唯一标识Tuple了)
  3. 主码(Primary Key): 用户自己选取一个Canditate Key做Primary Key,下划线标识
  4. 外码(Foreign Key): “链接”到其他table主码的一组Attributes --> referencing
  5. 全码(All Key): 由所有属性构成Canditate Key

参照关系&被参照关系:外码所在的Relation(table)叫做参照关系(Referencing Relation),是主动的一方;主码所在的Relation叫做被参照关系(Referenced Relation)

完整性约束

  1. 实体完整性:主码值不能为null
  2. 参照完整性:外码只能取被参照关系主码中存在的值 或 取null (新来的)
  3. 用户自定义完整性:Check

关系代数

  • 广义投影:投影列表中使用算数函数(聚集函数),必须将结果Rename

扩展操作

  1. 交 (Intersection): Difference
  2. θ-连接(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

  1. 除(Division):
    注意:R ÷ S: S的属性必须是R的真子集
    应用于:求全部的 / 所有的…的问题

关系运算的优先级

Project > Select > Product > Join = Division > Intersection > Union = Difference

关系演算

元组演算 / 域演算

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

猜你喜欢

转载自blog.csdn.net/qq_42347617/article/details/105286590