3 Data Modeling Using The Entity Relational Model

Database Management System · Unit 3 · 6 hrs

Data Modeling Using the Entity-Relational Model

Exam-focused notes for Data Modeling Using the Entity-Relational Model (Database Management System, CSC265): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.

Data Modeling Using the Entity-Relational Model in short

This unit covers conceptual database design with the entity-relationship model: the building blocks (entities, attributes, relationships), the notation used to draw them, the special case of weak entities, and the enhanced ER concepts of subclassing, specialization and generalization that let a design capture "is-a" hierarchies.

Data Modeling Using the Entity-Relational Model: notes

Using High-Level Conceptual Data Models for Database Design

Database design is normally carried out in a sequence of phases. First, requirements collection and analysis interviews the expected users of the database to document their data requirements (what must be stored) alongside the functional requirements of the application (what operations, or transactions, will be run against that data). Once requirements are understood, conceptual design builds a conceptual schema using a high-level, DBMS-independent data model such as the ER model, describing entity types, relationships and constraints; this schema is a faithful, concise description of the data requirements that is easy to review with the users who supplied them. Next, logical design (also called data model mapping) transforms this conceptual schema into the data model of a specific DBMS, for example a set of relational tables to be implemented in SQL. Finally, physical design specifies the internal storage structures: file organizations, indexes and access paths chosen to meet performance requirements. The entity-relationship (ER) model is the classical vehicle for conceptual design: it models the miniworld as a collection of entities and the relationships among them, and it deliberately concentrates on the schema of the database (its structure) rather than on any one instance of it.

Entity Types, Entity Sets, Attributes, and Keys

An entity is a thing or object in the real world with an independent existence, whether physical (a specific employee) or conceptual (a company, a course). An entity type defines a collection of entities that share the same attributes, for example every EMPLOYEE that a company records; the actual collection of entities of a given type present in the database at a point in time is its entity set, conventionally given the same name as the entity type even though the two are distinct concepts (one is a type definition, the other a population).

Attributes are the properties that describe an entity type; an EMPLOYEE entity might be described by name, age, address and salary, and each individual entity has its own value for every attribute. Attributes are further classified.

  • A simple attribute cannot be divided further; a composite attribute, such as Address, can be split into sub-parts (Street, City, State).
  • A single-valued attribute holds one value per entity; a multivalued attribute can hold a set of values, for example a Phone attribute if an employee can have several numbers.
  • A stored attribute holds a value directly; a derived attribute is computed from other attributes, for example Age derived from a stored Date of Birth.

A key attribute has a value distinct for every entity in the entity set, so it can be used to identify individual entities uniquely; an entity type may have more than one such candidate key, one of which is chosen as the primary key.

What this unit covers

  • Using High-Level Conceptual Data Models for Database Design
  • Entity Types, Entity Sets, Attributes, and Keys
  • Relationship Types, Relationship Sets, Roles, and Structural Constraints
  • Weak Entity Types
  • ER Diagrams, Naming Conventions, and Design Issues
  • Relationship Types of Degree Higher Than Two
  • Subclasses, Superclasses, and Inheritance
  • Specialization and Generalization
  • Constraints and Characteristics of Specialization and Generalization

Entity Types, Entity Sets, Attributes, and Keys

2080 · 5 marks

What is conceptual data model? Explain different types of attributes used in ER diagram. [5]

Show solved answer

Conceptual Data Model and Types of Attributes in ER Diagram


Conceptual Data Model (2 marks)

A conceptual data model is a collection of concepts used to describe the structure of a database at a high level of abstraction, independent of any physical implementation. It provides the necessary means to achieve abstraction and acts as a conceptual tool for describing data and the relationships among data.

  • It describes data at the logical and view level.
  • It focuses on what data is stored rather than how it is stored.
  • The most widely used conceptual data model is the Entity-Relationship (ER) Model.

The ER model describes the design of a database in terms of entities and relationships among them. An entity is an object in the real world with a set of attributes (e.g., customer_id, customer_name, customer_address).


Types of Attributes in ER Diagram (3 marks)

An attribute is a property or characteristic that describes an entity. The following types of attributes are used in ER diagrams:


1. Simple (Atomic) Attribute

  • An attribute that cannot be divided into smaller sub-parts.
  • It holds a single value.
  • Example: Roll_No, Age
  • Represented by an oval in ER diagram.

2. Composite Attribute

  • An attribute that can be divided into smaller sub-parts, each representing a more basic attribute.
  • Example: Name can be divided into First_Name, Middle_Name, Last_Name.
  • Represented by an oval connected to smaller ovals.

3. Single-Valued Attribute

  • An attribute that holds only one value for a particular entity.
  • Example: Date_of_Birth, SSN (Social Security Number).

4. Multi-Valued Attribute

  • An attribute that can hold more than one value for a single entity.
  • Example: Phone_Number (a person may have multiple phone numbers).
  • Represented by a double oval in ER diagram.

5. Derived Attribute

  • An attribute whose value can be derived or computed from another attribute.
  • Example: Age can be derived from Date_of_Birth.
  • Represented by a dashed oval in ER diagram.

6. Key Attribute

  • An attribute that uniquely identifies each entity in an entity set.
  • Example: Student_ID, Employee_ID.
  • Represented by an oval with the attribute name underlined.

7. Null Attribute

  • An attribute that may have a null (unknown or not applicable) value for some entities.
  • Example: Middle_Name may be null for some persons.

Summary Table

Attribute TypeDescriptionER Symbol
SimpleIndivisible, single valueOval
CompositeDivisible into sub-partsOval with sub-ovals
Single-ValuedOne value per entityOval
Multi-ValuedMultiple values per entityDouble Oval
DerivedComputed from other attributesDashed Oval
KeyUniquely identifies entityOval (underlined name)
NullMay have no valueOval
Open this answer on its own page →

2079 · 10 marks

What is entities and its types? How do we reduce different types of entities and relationships of ER diagram into Tables? Explain with assuming different types of entities and relations.[10]

Show solved answer

Entities, Their Types, and Reduction of ER Diagram to Tables


Part 1: Entity and Its Types

Definition of Entity

An entity is a real-world object or thing that has an independent existence and can be distinguished from other objects. For example: a Student, a Hotel, a Room, an Employee.

An entity type defines a collection of entities that have the same attributes. An entity set is the collection of all entities of a particular entity type at a given point in time.


Types of Entities

1. Strong Entity

A strong entity is an entity type that has a key attribute (primary key) which uniquely identifies each entity in the entity set. It does not depend on any other entity for its existence.

  • Represented by a single rectangle in the ER diagram.
  • Example: Hotel (identified by Hotel_ID), Employee (identified by Emp_ID)

2. Weak Entity

Entity types that do not have key attributes of their own are called weak entity types: their entity sets do not have sufficient attributes to form a primary key on their own.

Key characteristics of weak entities:

  • Cannot be identified on their own; they depend on an owner (strong) entity.
  • Always have total participation in the identifying relationship.
  • Represented by a double rectangle in the ER diagram.
  • The identifying relationship is represented by a double diamond.
  • Have a partial key (discriminator) instead of a full primary key.

Example: Room is a weak entity that depends on Hotel. A room cannot exist without a hotel.

[Hotel] ====<< has >>==== [[Room]]

3. Superclass and Subclass Entities (Specialization / Generalization)

  • Specialization is a top-down approach where a higher-level entity is broken into lower-level entities (subclasses).
  • Generalization is a bottom-up approach where lower-level entities are combined into a higher-level entity (superclass).

Example:

Employee (superclass)
    ISA
   /    \
Developer  Tester  (subclasses)

Part 2: Reduction of ER Diagram Components into Tables

As a general guideline, if a relation schema corresponds to one entity type or one relationship type, its meaning is straightforward to explain. If instead a relation corresponds to a mixture of multiple entities and relationships, semantic ambiguities result.

Therefore, each entity type and each relationship type should ideally map to one relation (table).


Rule 1: Mapping a Strong Entity to a Table

Each strong entity type becomes a separate table. The key attribute becomes the primary key.

Example:

ER Entity: Student(Student_ID, Name, Age, Email)

Table:

Student_ID (PK)NameAgeEmail
S01Ram20[email protected]
S02Sita21[email protected]
Student(Student_ID, Name, Age, Email)
PK: Student_ID

Rule 2: Mapping a Weak Entity to a Table

A weak entity becomes a table where:

  • The partial key of the weak entity is included.
  • The primary key of the owner entity is included as a foreign key.
  • The primary key of the weak entity table = (Owner's PK + Partial Key).

Example:

  • Strong Entity: Hotel(Hotel_ID, Hotel_Name, Location)
  • Weak Entity: Room depends on Hotel, with partial key Room_No and attribute Type

Tables:

Hotel(Hotel_ID, Hotel_Name, Location)
PK: Hotel_ID

Room(Hotel_ID, Room_No, Type)
PK: (Hotel_ID, Room_No)
FK: Hotel_ID references Hotel(Hotel_ID)
Hotel_ID (PK, FK)Room_No (PK)Type
H01101Deluxe
H01102Standard
H02101Suite

Rule 3: Mapping a 1:1 (One-to-One) Relationship

In a 1:1 relationship, the primary key of one entity is added as a foreign key in the other entity's table. Preferably, the foreign key is placed in the entity with total participation.

Example:

  • Employee(Emp_ID, Name) manages Department(Dept_ID, Dept_Name)
  • Relationship: Manages (1:1)

Tables:

Employee(Emp_ID, Name)
PK: Emp_ID

Department(Dept_ID, Dept_Name, Emp_ID)
PK: Dept_ID
FK: Emp_ID references Employee(Emp_ID)
Dept_IDDept_NameEmp_ID (FK)
D01ITE01
D02HRE02

Rule 4: Mapping a 1:N (One-to-Many) Relationship

The primary key of the "one" side entity is added as a foreign key in the table of the "many" side entity.

Example:

  • Department(Dept_ID, Dept_Name) has many Employee(Emp_ID, Name)
  • Relationship: Works_In (1:N)

Tables:

Department(Dept_ID, Dept_Name)
PK: Dept_ID

Employee(Emp_ID, Name, Dept_ID)
PK: Emp_ID
FK: Dept_ID references Department(Dept_ID)
Emp_IDNameDept_ID (FK)
E01RamD01
E02SitaD01
E03HariD02

Rule 5: Mapping an M:N (Many-to-Many) Relationship

Unlike 1:1 and 1:N relationships, an M:N relationship cannot be represented by simply adding a foreign key to either entity's table, because that would force each row to reference only one match on the other side. Instead, a new separate table (junction/bridge table) is created that contains:

  • The primary keys of both participating entities (as foreign keys).
  • Any attributes of the relationship itself.
  • A composite primary key made up of both foreign keys together.

Example:

  • Student(Student_ID, Name) enrolls in many Course(Course_ID, Course_Name), and a course has many students.
  • Relationship: Enrolls (M:N), with attribute Grade

Tables:

Student(Student_ID, Name)
PK: Student_ID

Course(Course_ID, Course_Name)
PK: Course_ID

Enrolls(Student_ID, Course_ID, Grade)
PK: (Student_ID, Course_ID)
FK: Student_ID references Student(Student_ID)
FK: Course_ID references Course(Course_ID)
Student_ID (FK)Course_ID (FK)Grade
S01C01A
S01C02B
S02C01A+

Summary

Every ER construct reduces to a relational table by the same underlying idea: strong entities become tables with their own primary key, weak entities inherit the owner's key as part of a composite key, 1:1 and 1:N relationships push a foreign key onto one existing table, and M:N relationships require a brand-new junction table carrying both sides' keys as a composite primary key. Applying these five rules to every entity and relationship in an ER diagram is what produces a complete, normalized relational schema.

Open this answer on its own page →

2076 · 5 marks

What is difference between Entities and Entity sets? Explain with example. [5]

An entity is a single, distinct real-world object or thing that exists independently and can be distinguished from other objects. It is a specific instance or occurrence of something in the real world that has some properties (attributes). An entity is an object in the real world with a set of at...

Open this answer on its own page →

Relationship Types, Relationship Sets, Roles, and Structural Constraints

2079 · 5 marks

Explain aggregation with example. [5]

Aggregation is an abstraction concept in the Entity-Relationship (ER) model where a relationship itself is treated as a higher-level entity. It allows a relationship between entities to participate in another relationship. In other words, aggregation is used to represent a relationship among rela...

Open this answer on its own page →

2078 · 5 marks

Explain Relationship and Relationship sets with example. [5]

A relationship is an association among two or more entities. It describes how entities from different entity sets are related to each other in the real world. For example, an employee works for a department. Here, "works for" is a relationship between the entity "Employee" and the entity "Departm...

Open this answer on its own page →

ER Diagrams, Naming Conventions, and Design Issues

2078 · 10 marks

What are the components of ER diagram? Explain the function of various symbols use in ER diagram. Construct an ER diagram to store data in a library of your college.[10]

An ER (Entity-Relationship) diagram helps to explain the logical structure of a database. It includes many specialized symbols, and their meanings make this model unique. The purpose of an ER diagram is to represent the entity framework infrastructure. It is a graphical tool that demonstrates the...

Open this answer on its own page →

Specialization and Generalization

2080.1 · 5 marks

What is specialization? What are different constraints on specialization? [5]

Specialization is a top-down approach in database design where one higher-level entity (superclass) is broken down into two or more lower-level entities (subclasses). It maximizes the differences between members of an entity by identifying the unique characteristics or attributes of each member. ...

Open this answer on its own page →