Lec 12 ERD Constraint, Generalization,Specialization EERD
Lec 12 ERD Constraint, Generalization,Specialization EERD
SYSTEMS
INSTRUCTOR: AYSHA
SAFDAR
Constraints in ERD and
EERD
1. Cardinality Constraints
Cardinality constraints define the number of instances of one entity that can be associated with instances of
another entity in a relationship. They are used to specify the minimum and maximum number of instances that
can be involved in a relationship.
One-to-One (1:1): One instance of Entity A is associated with at most one instance of Entity B, and vice versa.
◦ Example: A Person can have only one Passport, and a Passport can be associated with only one Person.
One-to-Many (1:N): One instance of Entity A can be associated with many instances of Entity B, but an
instance of Entity B can be associated with only one instance of Entity A.
◦ Example: A Department can have many Employees, but an Employee works in only one Department.
Many-to-One (N:1): Many instances of Entity A can be associated with one instance of Entity B, but each
instance of Entity A is associated with only one instance of Entity B.
◦ Example: Many Books can belong to one Author, but an Author can write many Books.
Many-to-Many (M:N): Many instances of Entity A can be associated with many instances of Entity B.
◦ Example: A Student can enroll in many Courses, and a Course can have many Students.
2. Participation Constraint
A participation constraint in an Enhanced Entity-Relationship Diagram (EERD) specifies
whether all instances of an entity participate in a relationship or not. There are two types of
participation constraints:
1. Total Participation
Definition: Every instance of an entity must participate in at least one relationship instance.
Notation: Represented with a double line connecting the entity to the relationship in the
diagram.
Example:
◦ In an employee-department relationship, if every employee must work in at least one department, the
participation of the Employee entity in the Works_In relationship is total.
◦ EERD Example:
◦ Entity: Employee
◦ Relationship: Works_In
◦ Constraint: Every Employee must work in at least one department.
2. Participation Constraint
2. Partial Participation
Definition: Some instances of an entity may not participate in the relationship.
Notation: Represented with a single line connecting the entity to the
relationship in the diagram.
Example:
◦ In an employee-project relationship, not every employee might be assigned to a
project. Therefore, the participation of the Employee entity in the Assigned_To
relationship is partial.
◦ EERD Example:
◦ Entity: Employee
◦ Relationship: Assigned_To
◦ Constraint: Some employees may not be assigned to any project.
3. Key Constraints
Key constraints define the uniqueness of an entity’s identifier or a
combination of attributes that uniquely identify an entity instance.
Primary Key (PK): A set of one or more attributes that uniquely identify an
entity instance.
◦ Example: The Student_ID attribute is the primary key of the Student entity.
Foreign Key (FK): A set of attributes in one entity that refers to the primary
key of another entity, establishing a relationship between the entities.
◦ Example: The Department_ID in the Employee entity refers to the primary key
Department_ID in the Department entity.
4. Disjoint and Overlapping
Constraints
(Specialization/Generalization)
These constraints are used in specialization and generalization hierarchies to specify
how instances of a superclass are divided into subclasses.
Disjoint Constraint: An entity instance in the superclass can only belong to one subclass
at a time. This constraint is used when the subclasses are mutually exclusive.
◦ Notation: Represented with a D inside a circle placed above the line connecting the superclass
and its subclasses.
◦ Example: A Person can either be a Teacher or a Student, but not both at the same time.
Overlapping Constraint: An entity instance in the superclass can belong to one or more
subclasses.
◦ Notation: Represented with an O inside a circle above the line connecting the superclass and its
subclasses.
◦ Example: An Employee can be both a Manager and a Salesperson.
5. ISA Relationship
(Specialization and
Generalization)
In ERDs, ISA (stands for Is-A) is used to indicate a relationship between a
superclass and its subclasses.
Car Truck
Child
Classes
Key enhancements in EERD
over ERD (…)
Specialization and Generalization:
Specialization Vehicle
Specialization is the process of breaking down
a general entity into more specific entities
based on certain distinguishing features or
attributes.
Characteristics:
◦ Starts with a general superclass entity and Top-
defines subclasses.
Down
◦ Subclasses inherit attributes and relationships of
the superclass. Approach
◦ Subclasses may add their own unique attributes
or participate in specialized relationships.
Generalization
Generalization is the process of
abstracting common features from two
or more specific entities to form a more Pare
general entity. nt
Class
Purpose: Combine similar entities into
a single general entity to reduce
redundancy.
Characteristics:
◦ Starts with specific subclasses and
merges them into a general superclass.
Child Child Child
class class class
◦ The superclass captures shared
attributes and relationships. 1 2 3 Bottom-up
Differences Between
Specialization and Generalization
{ Optional,
Generalizat Specializa
OR}
ion Languages tion
Text Book Novel
BOOK
Language Subject Type
Diagrammatic(UML)
representation of
Specialization/Generalization
Explanation
Disjoint Constraint
Superclass (Staff)
◦ Specifies whether subclasses overlap:
◦ Attributes: staffNo (PK), name, position, salary.
◦ Disjoint: A Staff entity belongs to only one subclass (e.g., either
◦ This represents the general entity containing Manager or SalesPersonnel).
shared attributes across all subclasses.
Relationships
Specialization (ISA Hierarchy) ◦ Branch has a 1:N relationship with Staff (indicating
multiple staff members work at one branch).
◦ Subclasses derived from Staff:
◦ Manager has a 1:1 relationship with Branch
◦ Manager (with attributes mgrStartDate and bonus).
(indicating a manager manages one branch).
◦ SalesPersonnel (with attributes salesArea and carAllowance).
◦ Secretary (with attribute typingSpeed). Specialization vs Generalization in the Diagram
◦ Indicates that Staff is specialized into these sub-
entities based on roles. Generalization: The Manager, SalesPersonnel, and
Secretary subclasses share common attributes like
Participation Constraint staffNo, name, position, and salary, which are
◦ Specifies whether an entity in the superclass generalized into the Staff superclass.
(Staff) must also belong to a subclass:
◦ {Optional, And}: Indicates partial participation, where a Staff
Specialization: The Staff superclass is specialized
member may belong to one or more subclasses. into three distinct roles, each with unique attributes.
EERD: Case Study
Imagine an online bookstore where customers can purchase both physical
books and eBooks. In this system, you need to represent customers, books,
and orders. Customers have a unique ID, a name, and an email and have been
members since a certain date. Books are characterized by an ISBN, title,
author, genre, and price. There are two types of books: physical books, which
also have a shipping weight, and eBooks, which have a file format. Orders are
placed by customers and include a unique order ID, the date, and the total
amount. The relationship between customers and orders is one-to-many, as a
customer can place multiple orders, but each order is placed by a single
customer. Each order can contain several books. The EERD should clearly
depict these entities with their attributes, the relationships with proper
cardinalities, and the specialization of books into physical books and eBooks.
Specialization
Constraints:
◦ Disjoint Constraint: A book can either be a physical book or an
eBook, not both.
Entities:
◦ Partial Participation: Not all Book entities must belong to a
Customer (Superclass): subclass. Some general information about books might be stored at
the superclass level.
◦ Attributes: Customer_ID (PK), Name, Email,
Member_Since.
Generalization
Book (Superclass):
it can be viewed as the reverse of specialization if focusing on
◦ Attributes: ISBN (PK), Title, Author, Genre, Price.
combining attributes of specific book types into the general Book entity.
An online learning platform allows students to enroll in courses. The platform offers two types of courses: Self-
Paced Courses and Instructor-Led Courses. Each course has a unique course ID, a title, a description, a
price, and a duration. Self-paced courses include the number of videos and downloadable resources, while
instructor-led courses include the instructor's name, meeting schedules, and maximum number of participants.
Students can enroll in multiple courses, and each course can have multiple students enrolled. When students
enroll in a course, an enrollment record is created with a unique enrollment ID, the date of enrollment, and the
payment status.
Requirements:
◦ Enrollment: 0..N (A student can have multiple enrollments, or none). Make EERD??
An Online Music Streaming Platform allows users (subscribers) to listen to and purchase different types of music content. The platform offers
two types of content: Albums and Singles. Each content piece has a unique content ID, a title, an artist, a release date, a price, and a genre.
Albums include additional attributes such as number of tracks, and duration, while Singles include attributes such as track length and
release year.
Users (subscribers) can subscribe to the platform and have the ability to listen to unlimited content during their subscription. A user can
purchase individual albums or singles. Purchase records are created when a user buys a specific content piece, containing a unique purchase
ID, the purchase date, and the payment status.
Requirements:
Represent users, content (albums and singles), and purchase records as entities.
An Online Retail Platform allows customers to purchase various products. The platform offers two types of products: Physical Products and
Digital Products. Each product has a unique product ID, name, description, price, and stock quantity.
Physical Products include attributes like weight, dimensions, and shipping fees, while Digital Products include attributes such as file
format and download link.
Customers can place orders for multiple products, and each order can contain multiple products. Each order has a unique order ID, order
date, payment status, and total amount. When customers place an order, an order record is created, tracking the items purchased.
Requirements: