数据库学习笔记

Posted on November 26, 2020 by τ

Data Models

A data model is collection of concepts for describing the data in a database.

A schema is a description of a particular collection of data, using a given data model.

Data Models:

  • Relational
  • Key/Value
  • Graph
  • Document
  • Column-family
  • Hierarchical
  • Network
  • Multi-Value

Relational Model

A relation is unordered set that contain the relationship of attributes that represent entities.

A tuple is a set of attribute values in the relation.

Keys

A relation’s primary key uniquely identifiers a single tuple.

A foreign key specifies that an attribute from one relation has to map to a tuple in another relation.

Relational Algebra

  • Select: Choose a subset of the tuples from a relation that satisfies a selection predicate.

    σpredicate(R)

  • Projection: Generate a relation with tuples that contains only the specified attributes.

    πA1, A2, ..., An(R)

  • Union:

    R ∪ S

  • Intersection:

    R ∩ S

  • Diffrence: Generate a relation that contains only the tuples that appear in the first and not the second of the input relations.

    R − S

  • Product: Generate a relation that contains all possible combinations of tuples from the input relations.

    R × S

  • Join: Generate a relation that contains all tuples that are a combination of two tuples with a common value(s) for one or more attributes.

    R ⋈ S

  • Rename:

    ρ

  • Assignment:

    R ← S

  • Duplicate Elimination:

    δ(R)

  • Aggregation:

    γ

  • Sorting:

    τ

  • Division:

    R ÷ S

SQL