Skip to content

1 Introduction & Relational Model

Data Models

Hierarchical Model

  • one-to-many relationships
  • tree

Network Model

  • many numbers of many-to-many relationships
  • introduced pointers
  • acyclic directed graph
  • records (vertices) and sets (edges)
  • several items with the same kind of records will use linked lists

Relational Model

  • many-to-many relationships
  • decomposing many-to-many relationship into two one-to-many relationships using intersection record

Relational Model

General Terminology

  • tuple: a row in a table (usually considered to be unordered and non-identical)
  • relation: a two-dimensional table of data
  • attribute: a column in a table (usually considered as unordered)
  • domain: the set of permissible values for a given attribute
  • schema: consisting of the name of the relation followed by its attributes
  • component: an atomic single value of an attribute (structure NG)
  • instance of a schema: the current contents of a relation

Keys in Relational Model

  • primary key: one key that uniquely identify tuples in the relation
  • secondary key: any key which is not primary
  • superkey: any set of attributes which satisfies uniqueness condition
  • key: a minimal superkey, no proper subset of the key is a superkey

ER Model

Entity: real-world object distinguishable from other objects. An entity is described using a set of attributes.

Entity Set: A collection of similar entities. All entities in an entity set have the same set of attributes. Each entity set has a key.

Relational Algebra

ordinary set operations

set-level

projection

the relation obtained by selecting attributes from the relation and remove others

selection

the set of tuples in R which satisfy the condition C

join

Let and be two relations that has some attributes in common.

Then the natural join of R and S is:

The theta join of R and S on condition C is: the set of elements of the cartesian product which satisfy the join condition C.

renaming

rename R to S, with attributes rename to .

bags

A bag is similar to a set, but allows multiple occurrences of an element.

duplicate elimination

If R is a relation then denotes duplicate elimination.

aggregation

operators: COUNT, SUM, MAX, MIN, AVG

Example: MAX(width)(Artworks)

grouping

If R is a relation, then an expression using grouping is:

Example:

extended projection

If R is a relation, then an expression using extended projection is:

Example:

sorting

Ordered by primary sort key then secondary sort key and so on.

outerjoin

Sometimes there is no matching tuple for some tuples and they got disappeared in the joined relation. So outerjoin would keep them leave the unmatched part a null value .

For R and S:

  • in left outerjoin, only dangling tuples from R are added
  • in right outerjoin, only dangling tuples from S are added

You could also define a outer theta-join using the same way as before.