Back to Dashboard

Chapter 3: The Entity-Relationship Model

Lecturer: Jane YOU, Compiler: Zhen, TONG

Before everything, The first lab is released, please follow the docs and implement it, which will do you good in your final project😗

Design DB in 3 Phases

First, let's have a high-level overview of the typical stages involved in designing a database. Let's break down 3 phases:

1. Initial Phase - Characterizing Data Needs:

2. Second Phase - Choosing a Data Model:

3. Final Phase - Moving to Implementation:

This phase involves transitioning from the abstract data model to the actual implementation of the database, which is the most exciting part! 😋 It includes two sub-phases:

a. Logical Design: - In the logical design phase, you decide on the database schema, which is the blueprint for the database structure. This includes defining tables, relationships between tables, primary keys, foreign keys, and attributes. - Business decisions are made to determine what specific attributes (data fields) should be recorded in the database to meet the users' needs. - Computer science decisions involve defining the relation schemas (tables) and how attributes should be organized within these schemas to ensure data integrity and efficiency.

b. Physical Design: - The physical design phase focuses on the actual storage and access mechanisms for the database. It involves decisions such as how data will be stored on disk, indexing strategies, partitioning, and optimization for performance. - This phase is where you consider factors like hardware capabilities, database management system (DBMS) selection, and tuning for efficient data retrieval and storage.

 

Caution❗

When designing a database schema, it's crucial to avoid redundancy and incompleteness while also considering that there can be multiple good design alternatives. Let's explore these concepts further:

1. Redundancy:

2. Incompleteness:

 

 

Good Design Approach😜

The Entity-Relationship (ER) model and normalization theory are two fundamental design approaches in database design. Let's explore each of these approaches in more detail:

1. Entity-Relationship Model:

2. Normalization Theory:

 

ER Model

Here are the key concepts and components of the ER model:

Entity Set:

 

Relationship Set:

Relationship Sets with Attributes

Degree of a Relationship Set

The degree of a relationship set refers to the number of entity sets participating in a relationship. In other words, it indicates how many entity sets are connected by a single relationship set, which is the same definition in graph theory.

Binary Relationship:

Higher-Degree Relationships (Ternary and Beyond):

Complex Attributes 🙄

Let's expand on each kind of attributes one by one :

1. Simple Attributes:

2. Composite Attributes:

3. Single-Valued Attributes:

4. Multivalued Attributes:

5. Derived Attributes:

6. Domain:

Now can you tell the difference of ❓

 

 

Mapping💘

Types of Mapping Cardinality Constraints for Binary Relationships:

  1. One-to-One (1:1) Relationship:

    • In a one-to-one relationship, each entity in one entity set is associated with exactly one entity in the other entity set, and vice versa.

    • Representation: Use a directed line (→) connecting the relationship set to both entity sets.

  2. One-to-Many (1:N) Relationship:

    • In a one-to-many relationship, each entity in one entity set can be associated with multiple entities in the other entity set, but each entity in the other entity set is associated with at most one entity in the first entity set.

    • Representation: Use a directed line (→) from the one side (with the "one" end) and an undirected line (—) from the many side (with the "many" end) connecting the relationship set to the entity sets.

  3. Many-to-One (N:1) Relationship:

    • In a many-to-one relationship, each entity in one entity set is associated with at most one entity in the other entity set, but each entity in the first entity set can be associated with multiple entities in the other entity set.

    • Representation: Use a directed line (→) from the many side (with the "many" end) and an undirected line (—) from the one side (with the "one" end) connecting the relationship set to the entity sets.

  4. Many-to-Many (N:N) Relationship:

    • In a many-to-many relationship, each entity in one entity set can be associated with multiple entities in the other entity set, and vice versa.

    • Representation: Use undirected lines (—) connecting the relationship set to both entity sets.

 

 

Primary Key for Relationship Sets:

Choice of Primary Key for Binary Relationship Sets:

 

Weak Entity🤔

Weak entity sets are essential for modeling entities whose existence depends on the existence of another entity, called the identifying entity.

Instead of having its own primary key, a weak entity set uses the attributes of the identifying entity set along with additional discriminator attributes to uniquely identify its entities.

Identifying Entity Set:

Discriminator Attributes:

Representation in E-R Diagrams:

Total Participation:

Primary Key for Weak Entity Sets:

 

Redundant Attributes😏

According to the ER Diagram, sometimes an attribute can be redundant like:

The dept_name in instructor entity is redundant, because the attribute has already been represented in the relationship.

Reduction to Relation Schemas🏆

Now it's time for us to sum everything we learn together!🥇

  1. Strong Entity Set: A strong entity set is represented as a schema with attributes corresponding to the entity's attributes, including the primary key.

    • Example: The "student" entity set is represented as the "student" schema with attributes (ID, name, tot_cred).

  2. Weak Entity Set: A weak entity set is represented as a schema that includes a column for the primary key of the identifying strong entity set. This schema also includes attributes specific to the weak entity set.

    • Example: The "section" weak entity set is represented as the "section" schema with attributes (course_id, sec_id, semester, year).

  3. Take care of attributes

    • Pay attention to everything we discussed about attributes

Representation of Relationship Sets:

Combination of Schemas: