Professional Documents
Culture Documents
Model.
2020/2021
Contents
1.1. Introduction.
1.2. Basic concepts.
1.3. Entities.
1.4. Attributes.
1.5. Relationships.
1.6. Constraints.
1.7. Associative entity.
1.8. Enhanced E-R Model.
1.9. Translation of the E-R Model to the Relational Model.
1.10. Understanding the E-R model.
1.1. Introduction.
● A data model is the result of modeling the data of a system.
You won’t start building a house without a model (the plan
made by an architect).
● A data model describes the data, relationships between
different data, semantics associated with data and
constraints of consistency.
● The data model is an essential way to communicate with the
Database Administrator (the one responsible to ensure the
correct and efficient operation of the System Databases).
Levels of data
abstraction
1.1. Introduction.
● Different data models are defined according to the level of
abstraction that we are studying: logical or conceptual models,
models based on registers, physical models, etc. One of the
most widely used models at the logical/conceptual level is the
Entity-Relationship (E-R) Model.
Some author call this table the relationship set for the relationship
and the members of the relationship set are the rows of the table.
1.3. Entities: Types.
● Weak entities:
● Strong entities: ○ The ones that depends on a strong
○ The ones whose existence does not entity for its existence.
depend on the existence of any other ○ It is denoted by the double rectangle.
entity in a schema. ○ Weak entity do not have a identifier,
○ It is denoted by a single rectangle. instead it has a partial identifier (or
○ A strong entity always has the primary discriminator) that uniquely
attribute or identifier in the set of discriminates the weak entities. The
attributes that describes the strong entity identifier of a weak entity is a
(we will see this later). It indicates that composite identifier formed from
each entity in a strong entity set can be the primary attribute of the strong
uniquely identified. entity and discriminator of the weak
entity.
3.3. Entities: Types.
Other examples:
Strong entity | Weak entity
Order | Order Item
Example 2: The existence of rooms is entirely Host | Logins
dependent on the existence of a hotel. So room can be
seen as the weak entity of the hotel.
Receipt Number
1.5. Relationships.
● Entities are linked to each other by relationships.
● Every relationship must have a name.
● A relationship does not exist by itself. It needs the entities to make sense.
x
x x
1.5. Relationships: Types.
1.- Unary (or Recursive) Relationship: Relationship which associates an entity
of the same type to itself. Example: A person belonging to the Employee entity is
the manager of other person of the same Employee entity using a relationship
works-for.
● An employee has a boss, and an employee is boss of 0
or more employees. What does it happen to the owner
of the enterprise?
VERY IMPORTANT: N-ary Relationship be understood as a unit. The relationship must be studied
from the perspective of each of the participating objects. It is the set of all those perspectives who
completely describes the interrelation.
1.5. Relationships: Types.
● Strong relationship: Relationship which associates several strong entities.
Example:
Source: here.
1.6. Constraints: Cardinality or degree of a relationship.
One-to-Many (1:N)
● Is where one occurrence in an entity relates to many
occurrences in another entity.
● For example, taking the employee and department entities
shown on the previous page, an employee works in one
department but a department has many employees.
● Therefore, there is a one-to-many relationship between
department and employee.
Source: here.
1.6. Constraints: Cardinality or degree of a relationship.
Many-to-Many (M:M or M:N or N:M)
● This is where many occurrences in an entity relate to many
occurrences in another entity.
● For example, an employee may work on several projects at the
same time and a project has a team of many employees.
● Therefore, there is a many-to-many relationship between employee
and project.
Source: here.
1.6. Constraints: Optional Relationships.
● A relationship may also be optional. Either end of
the relationship can include zero occurrences as
an option. This is defined by the business rules
of the system being implemented.
● Taking the three examples, the business rules
may be like this:
○ Not all employees have assigned a
company car. A car may not have assigned
an employee.
○ A new department is created with no
employees in it. But an employee MUST
have a department
○ A new project is defined with no employees
working on it. A new employee starts within
the company but he/she couldn’t have any
project assigned.
Source: here.
1.6. Constraints: Optional Relationships.
1 or (1,1) -> 1 and only 1
(not 0, not 1)
1.6. Constraints: Cardinality or degree of a relationship
(Crow’s Foot).
Source: https://www.cs.dartmouth.edu/~cs61/Resources/ERD_Relationship_Symbols_Quick_Reference.pdf
More info: https://stackoverflow.com/questions/33781451/crows-feet-one-vs-one-and-only-one
1.6. Constraints: Cardinality or degree of a relationship
(Crow’s Foot).
Source: https://www.cs.dartmouth.edu/~cs61/Resources/ERD_Relationship_Symbols_Quick_Reference.pdf
1.6. Constraints: Cardinality or degree of a relationship
(Crow’s Foot).
Source: https://www.cs.dartmouth.edu/~cs61/Resources/ERD_Relationship_Symbols_Quick_Reference.pdf
MySQL
Workbench…
BUT THIS IS
RELATIONAL
MODEL!!
1.6. Constraints: Cardinality or
degree of a relationship.
Chen notation
● http://codex.cs.yale.edu/avi/db-book/db6/slide-dir/PPT-dir/ch7.ppt
● http://www.cs.toronto.edu/~jm/2507S/Notes04/EER.pdf
Let’s work
P01:
● Exercise 1
● Exercise 4
1.7. Associative entity.
Source: https://stackoverflow.com/questions/47150141/what-is-the-right-way-to-use-associative-entity?rq=1
Let’s work
P01:
● Exercise 6
1.8. Enhanced E-R Model.
● Appears due to the insufficiency of the E-R model for complex
applications.
● EER stands for Enhanced ER or Extended ER.
● EER Model Concepts:
○ Includes all modeling concepts of basic ER
○ Additional concepts (we’ll only see a simple version):
■ subclasses/superclasses
■ inheritance (attribute and relationship inheritance)
■ specialization/generalization
1.8. Subclasses and superclasses.
superclass
(supertype)
subclasses
(subtypes)
1.8. Subclasses and superclasses.
● There may not be an occurrence in any subclass that is
not a member of the superclass, but there may be
occurrences of a superclass that do not belong to any
subclass.
● The hierarchy or relationship between a subclass and
the corresponding superclass is said to be of type is_a
or is_a_type_of.
● Engineer is_a Employee, Technician is_a Employee,
etc.
1.8. Subclasses and superclasses.
● Note: An entity that is member of a subclass represents
the same real-world entity as some member of the
superclass:
○ The subclass member is the same entity in a distinct
specific role.
○ An entity cannot exist in the database merely by being a
member of a subclass; it must also be a member of the
superclass.
○ A member of the superclass can be optionally included as a
member of any number of its subclasses.
1.8. Enhanced E-R Model. Inheritance.
SSN will be
the identifier
for the
subentities
1.8. Subclasses and superclasses.
● Example:
○ A salaried employee who is also an engineer belongs to the two
subclasses:
■ ENGINEER, and
■ SALARIED_EMPLOYEE
■ (and it belongs also to the superclass!!)
○ It is not necessary that every entity in a superclass be a member of
some subclass
1.8. Enhanced E-R Model. Inheritance.
● Inheritance...
○ a) … of attributes: The members of the subclasses inherit the attributes of
the superclasses to which they belong. E.g.: Given a specialization Employee
in Secretary, Technician, Engineer, the birth_date of a Secretary is the
attribute of the Employee entity who represents him/her. In addition,
subclasses may have their own attributes. E.g.: typing_speed as a Secretary
attribute.
○ b) ... of relations: a member entity inherits all the relations established for its
superclass. In addition, subclasses can establish their own relationships.
E.g.: If EMPLOYEE has a relationship called “WORKING”, it also applies to
the SECRETERY subclass emtity. However, the HOURLY_EMPLOYEE
inherits also the “WORKING” relationship but also have its own relationship
“BELONGS_TO”.
1.8. Enhanced E-R Model. Specialization.
Generalizing
CAR and
TRUCK into
the
superclass
VEHICLE
1.8. Enhanced E-R Model. Relation between
Specialization/generalization and subclass/superclass.
P01:
● Exercise 5
1.9. Translation of the E-R Model to the Relational Model.
DBA DBMS
1.9. Translation of the E-R Model to the Relational Model.
MULTIPLE RELATIONSHIPS
AND ASSOCIATIVE ENTITY:
● SUBJECT (code, name, hours)
● STUDENT (NIF, name, address,
birth_date)
● PROFESSOR (SSN, name, address)
● ASSESSMENT (sub_code*, NIF*,
prof_SSN*, mark)
1.9. Translation of the E-R
Model to the Relational Model.
Recursive Relationships:
● PERSON (NIF, name)
● MARRIAGE(NIF*, NIF_partner*,
start_date, end_date)
Recursive Relationships:
● PERSON (ID, name, ID_mother*,
ID_father*)
○ Can ID_mother/ID_father be
NULL?
1.9. Translation of the E-R Model to the Relational Model.
Recursive Relationships:
● SUBJECT (ID, name, hours)
● PREREQUISITE (ID*, ID_PRE*)
1.9. Translation of the E-R Model to the Relational Model.
Weak entities:
1.9. Translation of the E-R Model to the Relational Model.
Multivalued attributes: Create a new
relation that includes the primary key
of the relation and another field with
the attribute (the combination will be
the primary key, sometimes only the
attribute can be PK).
SECRETARY(SSN*, typing_speed)
TECHNICIAN(SSN*, tgrade)
ENGINEER(SSN*, eng_type)
1.9. Translation of the E-R Model to the Relational Model.
See:
● http://tinman.cs.gsu.edu/~raj/4710/sp03/ch9-part1.pdf
● https://utexas.instructure.com/files/35778319/download?download_f
rd=1
1.10. Understanding the E-R model with examples.
● An order has only an item in it…
● Price must be stored in the orders because it can change (but it won’t change
in the orders still done!!)