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.
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 answerHide 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:
Namecan be divided intoFirst_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:
Agecan be derived fromDate_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_Namemay be null for some persons.
Summary Table
| Attribute Type | Description | ER Symbol |
|---|---|---|
| Simple | Indivisible, single value | Oval |
| Composite | Divisible into sub-parts | Oval with sub-ovals |
| Single-Valued | One value per entity | Oval |
| Multi-Valued | Multiple values per entity | Double Oval |
| Derived | Computed from other attributes | Dashed Oval |
| Key | Uniquely identifies entity | Oval (underlined name) |
| Null | May have no value | Oval |
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 answerHide 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) | Name | Age | |
|---|---|---|---|
| S01 | Ram | 20 | [email protected] |
| S02 | Sita | 21 | [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:
Roomdepends onHotel, with partial keyRoom_Noand attributeType
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 |
|---|---|---|
| H01 | 101 | Deluxe |
| H01 | 102 | Standard |
| H02 | 101 | Suite |
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)managesDepartment(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_ID | Dept_Name | Emp_ID (FK) |
|---|---|---|
| D01 | IT | E01 |
| D02 | HR | E02 |
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 manyEmployee(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_ID | Name | Dept_ID (FK) |
|---|---|---|
| E01 | Ram | D01 |
| E02 | Sita | D01 |
| E03 | Hari | D02 |
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 manyCourse(Course_ID, Course_Name), and a course has many students.- Relationship:
Enrolls(M:N), with attributeGrade
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 |
|---|---|---|
| S01 | C01 | A |
| S01 | C02 | B |
| S02 | C01 | A+ |
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.
2076 · 5 marks
What is difference between Entities and Entity sets? Explain with example. [5]
Relationship Types, Relationship Sets, Roles, and Structural Constraints
2078 · 5 marks
Explain Relationship and Relationship sets with example. [5]
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]
Specialization and Generalization
2080.1 · 5 marks
What is specialization? What are different constraints on specialization? [5]
Make Unit 3 stick
Practice CSC265 with flashcards & quizzes