0% found this document useful (0 votes)
2 views

Lecture 5

The document outlines the process of transforming Entity-Relationship (ER) models into relational schemas through ER-to-Relational Mapping, ensuring data integrity, consistency, and normalization. It details steps for mapping strong and weak entities, relationships, multivalued attributes, and specialization/generalization, along with the importance of these mappings for optimized database performance. Additionally, it introduces Enhanced Entity-Relationship (EER) constructs and their mapping strategies to further enhance database design capabilities.

Uploaded by

zezoadnan10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 5

The document outlines the process of transforming Entity-Relationship (ER) models into relational schemas through ER-to-Relational Mapping, ensuring data integrity, consistency, and normalization. It details steps for mapping strong and weak entities, relationships, multivalued attributes, and specialization/generalization, along with the importance of these mappings for optimized database performance. Additionally, it introduces Enhanced Entity-Relationship (EER) constructs and their mapping strategies to further enhance database design capabilities.

Uploaded by

zezoadnan10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Relational Database Design Using ER-to-Relational Mapping

 Entity-Relationship (ER) modeling is a conceptual approach used


to design databases.
 The ER-to-Relational Mapping process transforms an ER model
into a relational schema suitable for implementation in a relational
database.
 This ensures data integrity, consistency, and normalization for
an optimized database structure.

1. Steps in ER-to-Relational Mapping

Step 1: Mapping Strong Entities

 Each strong entity in the ER model becomes a table (relation) in


the relational schema.
 Attributes of the entity become columns in the table.
 The primary key (PK) uniquely identifies each record.

Example:-

ER Model Entity: Student

 Attributes: Student_ID (PK), Name, Age, Department


 Relational Table:

CREATE TABLE Student (


Student_ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Department VARCHAR(50)
);

Step 2: Mapping Weak Entities

 A weak entity does not have a primary key of its own and depends
on a strong entity.
 It includes a foreign key (FK) referring to the strong entity.
Example:-

ER Model:

 Weak entity: Dependent (related to Employee)


 Attributes: Dependent_ID (PK), Name, Employee_ID (FK)
 Relational Table:

CREATE TABLE Dependent (


Dependent_ID INT PRIMARY KEY,
Name VARCHAR(50),
Employee_ID INT,
FOREIGN KEY (Employee_ID) REFERENCES
Employee(Employee_ID)
);

Step 3: Mapping Relationships

Relationships in an ER model are converted into tables or


foreign keys, depending on the cardinality (1:1, 1:M, M:N).
(a) One-to-One (1:1) Relationship

 The primary key of one table is set as a foreign key in


another table.
 Example: Each student has one advisor.

CREATE TABLE Advisor (


Student_ID INT PRIMARY KEY,
Advisor_ID INT,
FOREIGN KEY (Student_ID) REFERENCES Student(Student_ID),
FOREIGN KEY (Advisor_ID) REFERENCES
Professor(Professor_ID)
);
(b) One-to-Many (1:M) Relationship

 The primary key of one table is placed as a foreign key in


the other table.
 Example: One department has many students.
CREATE TABLE Student (
Student_ID INT PRIMARY KEY,
Name VARCHAR(50),
Department_ID INT,
FOREIGN KEY (Department_ID) REFERENCES
Department(Department_ID)
);
(c) Many-to-Many (M:N) Relationship

 A junction table is created to link both entities.


 Example: Students enroll in multiple courses, and
courses have multiple students.

CREATE TABLE Enrollment (


Student_ID INT,
Course_ID INT,
Grade CHAR(2),
PRIMARY KEY (Student_ID, Course_ID),
FOREIGN KEY (Student_ID) REFERENCES Student(Student_ID),
FOREIGN KEY (Course_ID) REFERENCES Course(Course_ID)
);

Step 4: Mapping Multivalued Attributes

 Multivalued attributes require a separate table, where


each row represents a single value for that attribute.
 Example: Employee has multiple phone numbers.
CREATE TABLE EmployeePhone (
Employee_ID INT,
Phone_Number VARCHAR(15),
PRIMARY KEY (Employee_ID, Phone_Number),
FOREIGN KEY (Employee_ID) REFERENCES
Employee(Employee_ID)
);

Step 5: Mapping Specialization and Generalization

 Generalization: A single table for the parent entity with


an attribute identifying the type.
 Specialization: Separate tables for each subclass, with a
foreign key referring to the superclass.

Example:

Generalized entity Vehicle, specialized into Car and Bike.


CREATE TABLE Vehicle (
Vehicle_ID INT PRIMARY KEY,
Brand VARCHAR(50)
);

CREATE TABLE Car (


Vehicle_ID INT PRIMARY KEY,
Car_Type VARCHAR(50),
FOREIGN KEY (Vehicle_ID) REFERENCES Vehicle(Vehicle_ID)
);

CREATE TABLE Bike (


Vehicle_ID INT PRIMARY KEY,
Bike_Type VARCHAR(50),
FOREIGN KEY (Vehicle_ID) REFERENCES Vehicle(Vehicle_ID)
);
2. Importance of ER-to-Relational Mapping

✔ Ensures Data Integrity – Proper relationships and constraints maintain data


accuracy.
✔ Reduces Data Redundancy – Normalization removes duplicate data.
✔ Enhances Query Performance – Structured relationships optimize searches and
joins.
✔ Provides Scalability – The design adapts as data grows over time.

Conclusion

 ER-to-Relational Mapping is a critical process that translates conceptual


models into physical database structures.
 It ensures an efficient, structured, and well-connected relational database.
 By applying relationships, normalization, and constraints, databases are
optimized for performance and consistency.
Mapping Enhanced ER (EER) Model Constructs to Relations

The Enhanced Entity-Relationship (EER) model extends the basic


Entity-Relationship (ER) model by incorporating additional features
such as specialization, generalization, inheritance, and categories
(union types).
When designing a relational database, the EER model must be mapped
into relational tables while preserving data integrity and relationships.

1. Key EER Model Constructs

The EER model introduces the following advanced concepts:

 Specialization (subclassing an entity into more specific entities)


 Generalization (combining similar entities into a higher-level
entity)
 Categories (union types) (an entity that can be a member of
multiple entities)
 Aggregation (representing relationships between relationships)

We will now explore how these constructs are mapped into relational
tables.

2. Mapping EER Constructs to Relational Tables

Step 1: Mapping Strong Entities

 A strong entity is mapped to a relation (table) in the relational


database.
 Each attribute becomes a column in the table, with one attribute
serving as the primary key (PK).

Example:-

EER Entity: Customer

 Attributes: Customer_ID (PK), Name, Email, Phone


 Relational Table:
CREATE TABLE Customer (
Customer_ID INT PRIMARY KEY,
Name VARCHAR(50),
Email VARCHAR(50),
Phone VARCHAR(15)
);

Step 2: Mapping Weak Entities

 A weak entity depends on a strong entity and does not have its
own primary key.
 It includes a foreign key (FK) referencing the strong entity.
 The primary key (PK) of the weak entity is usually a combination
of its own attribute + foreign key.

Example

EER Model:

 Weak entity: Dependent (related to Employee)


 Attributes: Dependent_ID, Name, Employee_ID (FK)
 Relational Table:

CREATE TABLE Dependent (


Dependent_ID INT,
Name VARCHAR(50),
Employee_ID INT,
PRIMARY KEY (Dependent_ID, Employee_ID),
FOREIGN KEY (Employee_ID) REFERENCES
Employee(Employee_ID)
);

Step 3: Mapping Specialization & Generalization

 Specialization: Creating separate tables for each subclass.


 Generalization: Creating a single table with a type attribute or
separate subclass tables.
Approaches for Mapping Specialization/Generalization

1. Single Table (Supertype Table with a Discriminator Attribute)


o One table for the general entity.
o A type attribute differentiates subclasses.

CREATE TABLE Employee (


Employee_ID INT PRIMARY KEY,
Name VARCHAR(50),
Salary DECIMAL(10,2),
Employee_Type VARCHAR(20) CHECK (Employee_Type IN
('Manager', 'Technician'))
);

2. Multiple Tables (One Table per Subclass)


o Each subclass has its own table.
o Each subclass table inherits the superclass’s key.

CREATE TABLE Manager (


Employee_ID INT PRIMARY KEY,
Bonus DECIMAL(10,2),
FOREIGN KEY (Employee_ID) REFERENCES
Employee(Employee_ID)
);

CREATE TABLE Technician (


Employee_ID INT PRIMARY KEY,
Skill VARCHAR(50),
FOREIGN KEY (Employee_ID) REFERENCES
Employee(Employee_ID)
);

Step 4: Mapping Categories (Union Types)

 Category (union type) occurs when a subclass inherits attributes


from multiple parent entities.
 Implemented using a common key in a separate table.
Example

Consider an entity "Person" which could be a Customer or Employee.

 The Person_ID is the common key.

CREATE TABLE Person (


Person_ID INT PRIMARY KEY,
Name VARCHAR(50)
);

CREATE TABLE Customer (


Person_ID INT PRIMARY KEY,
Purchase_History TEXT,
FOREIGN KEY (Person_ID) REFERENCES Person(Person_ID)
);

CREATE TABLE Employee (


Person_ID INT PRIMARY KEY,
Salary DECIMAL(10,2),
FOREIGN KEY (Person_ID) REFERENCES Person(Person_ID)
);

Step 5: Mapping Aggregation (Relationship between Relationships)

 Aggregation allows an entire relationship to be treated as an entity.


 Implemented by creating a new table for the aggregation.

Example

A Project is associated with multiple Suppliers, and the relationship


itself (Supply) has an attribute (Cost).

CREATE TABLE Supply (


Project_ID INT,
Supplier_ID INT,
Cost DECIMAL(10,2),
PRIMARY KEY (Project_ID, Supplier_ID),
FOREIGN KEY (Project_ID) REFERENCES Project(Project_ID),
FOREIGN KEY (Supplier_ID) REFERENCES Supplier(Supplier_ID)
);
3. Summary of Mapping Strategies

EER Construct Mapping Approach


Strong Entities Create a table for each entity with PK
Weak Entities Create a table with a foreign key (FK)
referencing a strong entity
One-to-One (1:1) Relationship Add FK in one table or create a separate table
One-to-Many (1:M) Relationship Add FK in the "many" side table
Many-to-Many (M:N) Relationship Create a junction table with PKs from both entities
Specialization (Disjoint) Single table with a discriminator column or separate
subclass tables
Generalization Single table or separate subclass tables
Categories (Union Types) A common parent table with separate subclass tables
Aggregation Create a separate table representing the relationship

4. Importance of EER Mapping

✔ Supports Complex Data Modeling: EER extends ER capabilities to


handle inheritance, categorization, and relationships between
relationships.
✔ Optimizes Database Performance: Proper mapping techniques
reduce data redundancy and improve query efficiency.
✔ Ensures Data Integrity: Using foreign keys and constraints
enforces referential integrity.
✔ Provides a Scalable and Flexible Design: Helps in database
normalization and future expansions.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy