Extended ER: Generalisation, Specialisation and Aggregation
The extended ER model adds inheritance to ER. Specialisation splits an entity into subclasses, generalisation combines subclasses into a superclass, and aggregation lets a whole relationship participate in another.
-
DBMS Fundamentals
- Data, Information and Databases
- What a DBMS Is and Why It Exists
- File System versus DBMS
- Advantages and Limitations of a DBMS
- Database Users and the Role of the DBA
- Three Level Architecture and Data Abstraction
- Logical and Physical Data Independence
- Schema, Instance and Metadata
- Database Applications and the Database System Environment
- Database Architecture
- Data Models
-
ER Model
- Entities, Entity Sets and Entity Types
- Types of Attributes in the ER Model
- Keys in the ER Model
- Relationships, Relationship Sets and Degree
- Cardinality and Participation Constraints
- Strong and Weak Entities
- Drawing and Reading ER Diagrams
- Extended ER: Generalisation, Specialisation and Aggregation
- Converting an ER Diagram into Relational Tables
- ER Design Projects
- Relational Model
- Relational Algebra
- Functional Dependencies
-
Normalisation
- Why Normalisation Exists: Anomalies and Redundancy
- First Normal Form
- Second Normal Form and Partial Dependency
- Third Normal Form and Transitive Dependency
- BCNF and BCNF Decomposition
- 4NF, 5NF, Multivalued and Join Dependencies
- Lossless Decomposition and Dependency Preservation
- Complete Worked Normalisation: Unnormalised to BCNF
- Denormalisation and When to Use It
Concept
The basic ER model cannot express two situations well: an entity type that has several distinct varieties, and a relationship that itself takes part in another relationship. The extended entity relationship model adds three features to handle them.
Specialisation
Specialisation is top down. You start with one entity type and identify subgroups that have attributes or relationships the others do not.
+------------+
| PERSON | emp_id, name, dob <- shared
+-----+------+
|
/
/ISA <- triangle
+-----+
/
+----------+ +----------+
| STUDENT | | LECTURER |
+----------+ +----------+
roll_no, staff_no,
programme designation, salary
Shared attributes live once, on PERSON.
Specific attributes live on the subclass that needs them.
A subclass INHERITS every attribute and relationship of
its superclass.Generalisation
Generalisation is bottom up and is the same structure reached from the other direction. You notice that CAR and TRUCK share registration, model and year, so you factor the common part out into VEHICLE.
| Specialisation | Generalisation | |
|---|---|---|
| Direction | Top down | Bottom up |
| Starts from | One general entity | Several specific entities |
| Produces | Subclasses | A superclass |
| Driven by | Differences | Similarities |
| Result | Identical — an ISA hierarchy. The difference is only how you arrived. | |
Constraints on a hierarchy
Two independent constraints apply, giving four combinations.
| Constraint | Options | Meaning |
|---|---|---|
| Disjointness | Disjoint (d) | An entity may belong to at most one subclass. |
| Overlapping (o) | An entity may belong to several subclasses. | |
| Completeness | Total | Every superclass entity must belong to some subclass. Double line. |
| Partial | An entity may belong to no subclass. Single line. |
disjoint + total every vehicle is a car or a truck,
never both
disjoint + partial an account is savings or current, and
some accounts are neither
overlapping + total every person is a student or staff,
and some are both
overlapping+partial a person may be a student, a staff
member, both, or neitherAggregation
Aggregation solves the second problem: a relationship needs to take part in another relationship, and the ER model has no way to connect a diamond to a diamond.
THE PROBLEM
EMPLOYEE ---< WORKS_ON >--- PROJECT
Now: a MANAGER supervises an employee working on a
particular project. Not the employee in general, and not
the project in general - the COMBINATION.
THE SOLUTION: treat the relationship as one abstract entity
+-------------------------------------+
| EMPLOYEE ---< WORKS_ON >--- PROJECT | <- aggregated
+------------------+------------------+
|
< SUPERVISES >
|
+--------+
| MANAGER|
+--------+
The dashed box is the aggregation. It says: this whole
relationship is now a single thing that can participate
in another relationship.Converting to tables
| Approach | What you create | Best when |
|---|---|---|
| One table per hierarchy | A single table with every attribute plus a type column. Unused columns are null. | Subclasses differ little; queries usually read all types together |
| One table per subclass | A table for each subclass containing shared and specific attributes. No superclass table. | The specialisation is disjoint and total |
| Superclass plus subclass tables | A superclass table, and one table per subclass holding only its own attributes plus the shared key. | Overlapping or partial hierarchies; the most flexible and the most joins |
Aggregation converts simply: the aggregated relationship becomes a table with its own primary key, and the outer relationship refers to that key.
Example
A bank
ACCOUNT ( acc_no, balance, opened_on )
ISA, disjoint, total
SAVINGS ( interest_rate )
CURRENT ( overdraft_limit )
Superclass plus subclass tables:
accounts ( acc_no PK, balance, opened_on, acc_type )
savings ( acc_no PK and FK -> accounts, interest_rate )
current ( acc_no PK and FK -> accounts, overdraft_limit )
Disjoint is enforced by acc_type plus a check that a row
exists in only one subclass table. Total is enforced by
requiring every account to appear in one of them.Common mistakes
- Treating generalisation and specialisation as different structures. The result is the same hierarchy; only the direction of thought differs.
- Forgetting the constraints. A hierarchy without disjointness and completeness marked is incomplete, and marks are lost.
- Using aggregation where a plain ternary relationship would do. Aggregation is for when a relationship must participate in another relationship.
- Confusing aggregation here with the aggregate functions of query languages. Same word, unrelated meanings.
- Creating a hierarchy for two attributes. If the subclasses barely differ, one table with a type column is simpler and faster.
Exam and interview questions
- Differentiate generalisation and specialisation.
- Explain disjoint and overlapping, total and partial, with an example of each combination.
- What is aggregation in the ER model, and which problem does it solve?
- Describe three ways to convert an ISA hierarchy into tables, with the trade offs.
- Give an example of an overlapping specialisation.
Practice
- Draw a specialisation of EMPLOYEE into PERMANENT and CONTRACT, and state both constraints.
- Model a university where a person may be both a student and a staff member. Which disjointness constraint applies?
- Give a case needing aggregation and convert it to tables.
Conclusion
Specialisation goes top down, generalisation bottom up, and both produce an ISA hierarchy constrained by disjointness and completeness. Aggregation lets an entire relationship behave as one entity so it can participate in another — the one thing basic ER cannot express.