Entity-Relationship Diagrams

  1. Entity Type
    • an object in the real world that is distinguishable from other objects
  1. Entity Set
    • a collection of entities of the same type
  1. Attributes
    • the properties that define the entity type
  1. Key Attribute
    • a uniquely identifies each entity in the entity set
  1. Relationship Type
    • represents the association between entity types
  1. Relationship Set

Key

  1. Super key

    • A superkey is any set of one or more attributes that can uniquely identify an entity in a table.
    • It doesn’t have to be the smallest set of attributes that can do so.
  2. Candidate key

    • A candidate key is a superkey for which no proper subset is also a superkey.
    • It is a minimal set of attributes that can uniquely identify an entity in a table.
  3. Primary key

    • A primary key is a candidate key that has been selected as the main key for a table.
    • There can only be one primary key per table.

Constraints

Key Constraints

  1. One-to-one
    • An entity in A is associated with at most one entity in B.
    • An entity in B is associated with at most one entity in A.
      • a man may be married to at most one woman, and a woman may be married to at most one man.
  1. One-to-many
    • An entity in A is associated with any number in B.
    • An entity in B is associated with at most one entity in A.
      • each child can have at most one mother, but a mother may have more than one children.
  1. Many-to-one
    • An entity in A is associated with at most one entity in B.
    • An entity in B is associated with any number in A.
      • an employee can only work in at most one department, but a department has more than one employees.
  1. Many-to-many
    • Entities in A and B are associated with any number from each other.
      • both boy and girl can have more than one girl and boy classmates resepectively.

Participation Constraints

  • The example of a one-to-one key constraint, noting that a man may be married to at most one woman, and a woman may be married to at most one man (both men and women can be unmarried). Suppose we want to build a database for the “Married Persons Association”. In this case everyone must be married! In database terms their participation must be total.

  • If the participation of an entity set in a relationship set is total, they must be connected by a bold link.

Weak Entity

  • Strong Entity
    • An entity which has a super key.
    • Each entity can be distinguished from other entities.
  • Weak Entity

    • An entity without super key (only has a partial key).
    • May not be able to distinguish from other entities without associations with entities in other entity sets.

Other Relationships

Ternary Relationships

  • It is possible to have higher order relationships, including ternary relationships.

  • NOTED: Every ternary (and higher order) relationship can be converted into a set of binary relationships.

  • NOTED: A non-binary relationship set cannot be replaced by a number of binary relationship sets.
    The ternary relationship cannot be convert into these relationships !!!

Class Hierarchies

  • Sometimes it is natural to classify the entities in an entity set into subclasses.

Aggregation

  • Model a relationship between a collection of entities and relationships.
  • Aggregation allows us to indicate that a relationship set participates in another relationship set.