Entity-Relationship Model
Entity-Relationship Diagrams

- Entity Type
- an object in the real world that is distinguishable from other objects

- an object in the real world that is distinguishable from other objects
- Entity Set
- a collection of entities of the same type

- a collection of entities of the same type
- Attributes
- the properties that define the entity type

- the properties that define the entity type
- Key Attribute
- a uniquely identifies each entity in the entity set

- a uniquely identifies each entity in the entity set
- Relationship Type
- represents the association between entity types

- represents the association between entity types
- Relationship Set

Key
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.
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.
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
- 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.

- a man may be married to at most one woman, and a woman may be married to at most one man.
- 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.

- each child can have at most one mother, but a mother may have more than one children.
- 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.

- an employee can only work in at most one department, but a department has more than one employees.
- 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.

- both boy and girl can have more than one girl and boy classmates resepectively.
- Entities in A and B are associated with any number from each other.
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.



