数据库

数据库语言

  1. SQL 语言:
    1. 数据定义语言(DDL)define
    2. 数据操纵语言(DML)management
    3. 数据控制语言(DCL)control

Drawbacks of DBS

  • data redundancy and inconsistency
    • duplication of info in differ files
    • cost high
  • data isolation
    • multiple files and formats
  • diffi in accessing data
  • data updates differently
  • access by many users at same time
  • security

View of data

  • abstraction view
    • physical level: 是数据库用户能够看见和使用的逻辑结构和特征的描述,与某一应用相关的数据的逻辑表示
    • logical level : 是数据库中所有数据的逻辑结构和特征的描述
    • view level

Independence

  • phy data independence : application dont depend on phy schema
  • logical data independence: 保护用户不受数据逻辑结构变化的影响

Basic structure

  • tuple: row
  • attributes : column name
  • degree/arity: number of attributes
  • cardinality (基数): number of tulpes
  • relation schema:

Keys

  1. super key:能唯一标识 rowattribute/attributes,可能包含 extraneous attributes,不唯一
  2. candidate key : 能唯一标识 rowattribute/attributes,不唯一。是 mininal super key 。If any proper subset of a super key is a super key then that key cannot be a candidate key
  3. prime attribute:至少属于一个 candidate key 的 `attribute
  4. Foreign keys : 外键

模式和视图

  • 模式(数据的结构):对数据库中数据进行的一种结构性的描述
  • 视图(展现的数据):某一表现形式下表现出来的数据库中的数据

关系模型

关系模型的完整性

  1. 实体完整性
    1. 主码的属性值不能为空值
  2. 参照完整性 (关系间连接的正确性))
    1. 如果关系 R 1 的外码 Fk 与关系 R 2 的主码 Pk 相对应,则 R 1 中的每一个元组的 Fk 值等于 R 2 中某个元组的 Pk 值或者为空值
  3. 用户自定义完整性

关系代数

第4讲 关系模型之关系代数_哔哩哔哩_bilibili

  1. 基本操作:
    1. 差(difference)
    2. 笛卡尔积(product):
      1. R 和 S 中的元组进行所有可能的拼接; R × S=R × S;
      2. 元组数目=R * S ;
      3. 属性数目=R+S
    3. 选择(select)
      1. r 是关系/表名
    4. 投影(projection):
      1. 从若干列中选出某列
    5. rename operation:
  2. 扩展操作:
    1. 连接 (join)
      1. 等值连接
      2. 自然连接
        1. 特殊的等值连接:相同的属性组去掉
      3. left join/right join/full outer join
    2. 除(division)(派生运算符)
      1. R ÷ S :R divided by S
      2. 一般用于求解”查询····全部的/所有的”的问题
    3. Aggregate/sum
      1. Take collection of values, returns a single value