CSC265 Database Management System

Database Management SystemUnit 311 min read

Unit 3: Data Modeling Using the Entity-Relationship Model – Key Concepts and Applications

Unit 3 of Database Management System: covers data abstraction, ER modeling, schema design, constraints, specialization/generalization, and practical diagram construction for real‑world scenarios.

Key points

  • ER modeling provides a visual, high‑level abstraction of real‑world entities and their relationships.
  • A schema defines the structure; an instance is a particular set of tuples that satisfies the schema.
  • Data independence is achieved through a three‑schema architecture separating user, conceptual, and internal views.
  • Constraints (domain, entity, referential) enforce data integrity at the model level.
  • Specialization and generalization enable hierarchical classification of entities, improving reuse and expressiveness.

1. Introduction to Data Modeling

Data modeling is the process of creating a conceptual representation of data requirements and constraints. It bridges the gap between business requirements and the physical database implementation. In DBMS, the Entity‑Relationship (ER) model is the most widely taught conceptual model because it closely mirrors human understanding of the problem domain.

1.1 Data Abstraction

  • Data abstraction is the process of hiding the details of data representation and focusing on the logical structure.
  • It allows users to interact with the database without needing to know how data is stored physically.

1.2 Data Model

  • A data model is a formal description of the structure, semantics, and constraints of data.
  • It defines entities, attributes, relationships, and integrity rules.

1.3 Schema, Instance, and Database State

Term Definition Example
Schema The logical structure of the database (tables, columns, constraints). Customer(id, name, email)
Instance A particular set of tuples that satisfy the schema at a point in time. Customer(1, 'Alice', 'alice@example.com')
Database State The collection of all instances at a given time. All current rows in all tables.

The schema is static; the instance changes as data is inserted, updated, or deleted. The database state is the snapshot of the instance at a particular moment.

2. Data Independence and Three‑Schema Architecture

2.1 Data Independence

  • Logical data independence: Ability to change the conceptual schema without affecting external schemas.
  • Physical data independence: Ability to change the internal schema without affecting the conceptual schema.

2.2 Three‑Schema Architecture

Layer Purpose Example
External User views; tailored to specific application needs. A librarian’s view showing only books and borrowers.
Conceptual Global view of the entire database; defines all entities and relationships. The complete ER diagram of the library system.
Internal Physical storage details; indexes, file organization. B‑tree index on Book.isbn.

This separation ensures that changes at one level do not ripple through the entire system, preserving data independence.

3. Relational Constraints in the ER Context

Although ER modeling is conceptual, it maps to relational constraints once translated.

3.1 Domain Integrity

  • Each attribute must belong to a predefined domain (data type and permissible values).
  • Example: age must be an integer between 0 and 120.

3.2 Entity Integrity

  • Primary key of an entity must be unique and non‑NULL.
  • Example: Customer.id must be unique and not null.

3.3 Referential Integrity

  • Foreign keys must reference existing primary keys or be NULL.
  • Example: Order.customer_id must reference an existing Customer.id.

These constraints are enforced by the DBMS to maintain consistency.

4. Core ER Modeling Concepts

4.1 Entities and Entity Sets

  • Entity: A real‑world object with a distinct existence.
  • Entity Set: Collection of similar entities.
  • Example: Book entity set contains all books.

4.2 Attributes

  • Properties of entities.
  • Simple: indivisible (e.g., first_name).
  • Composite: composed of multiple simple attributes (e.g., address = street, city, zip).
  • Multivalued: can have multiple values (e.g., phone_numbers).
  • Derived: computed from other attributes (e.g., age derived from birth_date).

4.3 Relationships and Relationship Sets

  • Relationship: Association between two or more entity sets.
  • Relationship Set: Collection of specific relationships.
  • Example: Borrows relationship between Student and Book.

4.4 Cardinality and Participation Constraints

Symbol Meaning Example
1 One One Author writes many Books.
N Many Many Students borrow many Books.
Mandatory Participation must occur Every Order must be placed by a Customer.
Optional Participation may not occur A Book may not have an Editor.

4.5 Specialization and Generalization

  • Generalization: Abstracting common attributes/relationships into a super‑entity.
    • Example: Vehicle super‑entity with Car, Truck, Motorcycle subclasses.
  • Specialization: Splitting an entity into more specific subclasses.
    • Example: Employee specialized into Manager and Staff.

4.5.1 Constraints in Specialization/Generalization

Constraint Definition Example
Disjoint Subclasses are mutually exclusive. A person cannot be both Student and Faculty.
Complete Every entity of the super‑entity must belong to at least one subclass. Every Vehicle must be a Car, Truck, or Motorcycle.
Partial Some entities may not belong to any subclass. Some Vehicles are unclassified.

5. ER Diagram Construction

5.1 Diagram Symbols

Symbol Representation Example
Rectangle Entity Customer
Ellipse Attribute name
Diamond Relationship Places
Double rectangle Weak entity OrderItem
Double ellipse Multivalued attribute phone_numbers
Underlined attribute Primary key Customer.id
Dashed line Derived attribute age
Lines with crows‑foot Cardinality 1:N

5.2 Worked Example: Online Bookstore

Scenario:

  • Customers place orders.
  • Each order contains one or more books.
  • Books have authors.

Step 1: Identify Entities

  • Customer, Order, Book, Author.

Step 2: Identify Attributes

  • Customer: customer_id (PK), name, email.
  • Order: order_id (PK), order_date.
  • Book: isbn (PK), title, price.
  • Author: author_id (PK), name.

Step 3: Identify Relationships

  • Places: Customer – Order (1:N).
  • Contains: Order – Book (N:M).
  • Writes: Author – Book (1:N).

Step 4: Add Cardinality

  • Customer 1 – N Order.
  • Order N – M Book (via associative entity OrderItem).
  • Author 1 – N Book.

Step 5: Draw Diagram

+-----------+          +-----------+          +-----------+
| Customer  |          |   Order   |          |   Book    |
|-----------|          |-----------|          |-----------|
| customer_id PK |<---1 | order_id PK |---N>---| isbn PK   |
| name      |          | order_date |          | title     |
| email     |          +-----------+          | price     |
+-----------+                |                 +-----------+
                              |
                              | N
                              v
                        +-----------+
                        | OrderItem |
                        |-----------|
                        | order_id FK|
                        | isbn FK    |
                        | quantity   |
                        +-----------+

Explanation:

  • OrderItem is an associative entity resolving the N:M relationship between Order and Book.
  • OrderItem contains the foreign keys order_id and isbn, and an attribute quantity.

5.3 Library System Example

Scenario:

  • Library has Books, Members, and Loans.
  • Each book can be borrowed by many members over time.
  • Each member can borrow multiple books.

Entities & Attributes

Entity Attributes
Book isbn PK, title, author, publisher, year
Member member_id PK, name, address, phone
Loan loan_id PK, loan_date, return_date

Relationships

  • Borrows: Member – Loan (1:N).
  • Contains: Loan – Book (N:M via LoanItem).

ER Diagram (ASCII)

+-----------+          +-----------+          +-----------+
|  Member   |          |   Loan    |          |   Book    |
|-----------|          |-----------|          |-----------|
| member_id PK |<---1 | loan_id PK |---N>---| isbn PK   |
| name      |          | loan_date |          | title     |
| address   |          | return_date|         | author    |
| phone     |          +-----------+          | publisher |
+-----------+                |                 | year      |
                              | N
                              v
                        +-----------+
                        | LoanItem  |
                        |-----------|
                        | loan_id FK|
                        | isbn FK   |
                        | due_date  |
                        +-----------+

6. Comparison: ER Model vs. Relational Model

Aspect ER Model Relational Model
Abstraction Level Conceptual, high‑level Logical, table‑based
Primary Focus Entities, relationships Tables, tuples
Expressiveness Supports complex relationships, hierarchies Limited to flat tables
Use Case Design phase, documentation Implementation phase
Mapping Translated to tables via ER‑to‑Relational mapping Native to DBMS
Advantages Intuitive, business‑centric Efficient for query processing
Disadvantages Can become complex for large systems Less intuitive for non‑technical stakeholders

7. Advantages and Disadvantages of ER Modeling

Advantages

  • Visual clarity: Easy to communicate with stakeholders.
  • Early error detection: Constraints and cardinalities identified before coding.
  • Reusable components: Generalization/specialization promote reuse.
  • Documentation: Serves as a blueprint for developers and DBAs.

Disadvantages

  • Scalability issues: Very large ER diagrams become unwieldy.
  • Ambiguity: Without strict notation, interpretations may vary.
  • Mapping overhead: Requires careful translation to relational schema.

8. Database Users and Their Roles

User Type Role Example
End Users Interact with applications. Library patrons.
Application Developers Build interfaces and logic. Web developers for bookstore.
DBAs Manage database, performance, backup. Database administrator for TU.
System Analysts Translate requirements into models. Analyst designing library system.
Data Architects Define overall data strategy. Architect of TU’s data warehouse.

Data independence ensures that changes in the schema do not disrupt these users’ interactions.

9. Advantages of DBMS over Traditional Filing Systems

Feature Traditional File System DBMS
Data Redundancy High Minimal (normalization)
Data Consistency Manual checks Integrity constraints
Concurrent Access Limited Multi‑user concurrency control
Security File‑level Fine‑grained access control
Backup & Recovery Manual Automated, point‑in‑time recovery
Query Capability Sequential search Declarative SQL, indexing

10. Summary of Key Terms

Term Definition
Data Raw facts and figures.
Database Organized collection of data.
DBMS Software that manages databases.
Database System DBMS + database + applications.
Database Catalog Metadata repository (system tables).

11. Exam Tip

  • Understand the mapping: Be able to convert an ER diagram to a relational schema (tables, primary keys, foreign keys).
  • Practice cardinality: Draw the correct crows‑foot notation for 1:N, N:M, and 1:1 relationships.
  • Specialization/Generalization: Know the difference between disjoint/overlapping and complete/partial constraints.
  • Constraints: Be ready to write domain, entity, and referential integrity rules in natural language.
  • Diagram construction: Given a scenario, sketch the ER diagram within 5–10 minutes; practice with varied examples (library, bookstore, hospital).
  • Past questions: Re‑create the bookstore scenario and the library diagram; annotate each entity, attribute, and relationship with keys and cardinalities.

By mastering these concepts, you will confidently tackle both descriptive and diagrammatic questions in the unit.

Based on the TU BSc CSIT syllabus for Database Management System (CSC265), unit 3.

Discussion

Loading…