0% found this document useful (0 votes)
5 views211 pages

Final Explanation

The document provides an overview of Relational Algebra and Normalization, essential concepts for understanding relational databases. It details various operations in Relational Algebra, including unary and binary operations, as well as the normalization process aimed at reducing redundancy and ensuring data integrity. Key steps in normalization are outlined, including functional dependencies and the progression through normal forms, alongside practical examples and study tips for exam preparation.

Uploaded by

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

Final Explanation

The document provides an overview of Relational Algebra and Normalization, essential concepts for understanding relational databases. It details various operations in Relational Algebra, including unary and binary operations, as well as the normalization process aimed at reducing redundancy and ensuring data integrity. Key steps in normalization are outlined, including functional dependencies and the progression through normal forms, alongside practical examples and study tips for exam preparation.

Uploaded by

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

To help you understand the uploaded files effectively for your exam, I will summarize the key

concepts and break down the topics covered in the files. Here's a structured overview based on
the content of the documents on Relational Algebra and Normalization.

1. Relational Algebra (Key Concepts and Operations)


Overview:

 Relational algebra is a procedural query language for relational


databases.
 It consists of operations to retrieve and manipulate data.
 The result of each operation is a new relation (table), ensuring closure.

Types of Operations:

a) Unary Operations (Applied to a single relation):

1. SELECT (σ)
o Filters rows based on conditions.
o Example: σ DNO=4 (EMPLOYEE) retrieves employees from
department 4.
o Properties:
 Commutative: σ(cond1)(σ(cond2)(R)) = σ(cond2)(σ(cond1)(R))
 Can be cascaded.

2. PROJECT (π)
o Selects specific columns (attributes).
o Example: π LNAME, FNAME, SALARY (EMPLOYEE)
o Properties:
 Removes duplicates.
 Not commutative.

3. RENAME (ρ)
o Renames relation or attributes for clarity.
o Example: ρ EmpNames (FNAME, LNAME) (EMPLOYEE)

b) Operations Based on Set Theory (Binary Operations):

1. UNION (∪)
o Combines tuples from two relations (eliminates duplicates).
o Both relations must be union-compatible (same attributes and
types).
o Example: RESULT1 ∪ RESULT2

2. INTERSECTION (∩)
o Returns tuples common to both relations.
o Example: EMPLOYEE ∩ MANAGER

3. SET DIFFERENCE (−)


o Returns tuples present in one relation but not in the other.
o Example: EMPLOYEE − MANAGER

4. CARTESIAN PRODUCT (×)


o Combines every tuple from two relations, creating all possible
pairs.
o Resulting tuples can be filtered using SELECT to obtain
meaningful results.
o Example: EMPLOYEE × DEPARTMENT

c) Binary Relational Operations:

1. JOIN
o Combines related tuples from different relations based on a
condition.
o Types:
 Inner Join
 Outer Join (Left, Right, Full)
o Example: EMPLOYEE ⨝ DNO=DEPT_NO DEPARTMENT

2. DIVISION
o Used for queries involving "for all" conditions.
o Example: Find employees who have worked on all projects.

d) Additional Operations:

1. Aggregation Functions (SUM, COUNT, AVG, MIN, MAX)


o Compute summary statistics on relations.
o Example: COUNT(EMPLOYEE)

2. Outer Union
o Combines relations with different attributes while preserving
unmatched tuples.
e) Relational Algebra Expressions

 Combining multiple operations to achieve complex queries.


 Example:
 π FNAME, LNAME, SALARY (σ DNO=5 (EMPLOYEE))

Retrieves names and salaries of employees in department 5.

2. Normalization (Database Optimization for Efficiency)


Purpose:

 Reduce redundancy and anomalies (insertion, deletion, modification).


 Ensure data consistency by decomposing relations.

Normalization Process:

1. Functional Dependencies (FDs):


o A relationship where one attribute uniquely determines another.
o Example: ENO → ENAME

2. Steps in Normalization:
o First Normal Form (1NF):
 Eliminate repeating groups; ensure atomicity.
 No multi-valued or composite attributes.
 Example: Converting a list of phone numbers into separate
rows.

o Second Normal Form (2NF):


 Remove partial dependencies (every non-prime attribute
depends on the entire key).
 Example: If EMPLOYEE_ID → NAME, DEPT_ID and DEPT_ID →
DEPT_NAME, it should be decomposed.

o Third Normal Form (3NF):


 Remove transitive dependencies.
 Non-prime attributes should depend only on the primary
key.
 Example: If EMPLOYEE_ID → TITLE and TITLE → SALARY, then
salary should not be dependent on title.
o Boyce-Codd Normal Form (BCNF):
 Every determinant should be a candidate key.
 Stronger than 3NF by eliminating anomalies not covered by
3NF.

Examples of Anomalies Resolved by Normalization:

1. Insertion Anomaly:
o Cannot insert a new department without an employee.

2. Deletion Anomaly:
o Deleting an employee may remove critical project data.

3. Modification Anomaly:
o Updating a budget requires changes in multiple rows.

Functional Dependency Inference Rules (Armstrong's Axioms):

 Reflexivity: If Y is a subset of X, then X → Y.


 Augmentation: If X → Y, then XZ → YZ.
 Transitivity: If X → Y and Y → Z, then X → Z.

Decomposition Approach for Normalization:

1. Identify functional dependencies.


2. Decompose into smaller relations while preserving dependencies.
3. Ensure the decomposition is lossless and dependency-preserving.

Exercises to Practice:

1. Given relation:
STUDENT (Student#, Module#, S_name, Age, Address, M_title, Inst_code,
Inst_name, Sem, Grade)

Functional dependencies:

o Student# → S_name, Age, Address


o Module# → M_title, Inst_code
o Inst_code → Inst_name
o Student#, Module# → Grade

Steps:

o Convert to 1NF, 2NF, and 3NF.

2. Project Database Example:


o Employees working on multiple projects, with budget and
responsibilities.

Study Tips for Exam:

1. Understand Concepts:
o Practice identifying SELECT, PROJECT, JOIN operations in
relational algebra.
o Review normalization by working on sample tables.

2. Memorize Important Properties:


o Closure, commutativity, associativity, and distributive properties.

3. Solve Practical Examples:


o Write relational algebra expressions for business scenarios.
o Normalize sample databases to higher normal forms.

4. Compare and Contrast:


o Differences between normal forms and their significance.

Would you like specific explanations on any topic or assistance with practice questions?

Ch 7

Here’s a breakdown of the Normalization content in the uploaded document


to help you study for your exam efficiently.

1. Normalization Overview
Normalization is a process in database design that organizes data to:

Reduce data redundancy.

Eliminate insertion, deletion, and modification anomalies.

Ensure data integrity and consistency.

Steps in Database Design:

1. ER-to-Relational Mapping: Convert ER diagrams to relational schema.

2. Normalization: Improve the schema to avoid anomalies.

3. Relational Design Principles

Relations should have semantic unity (one theme per table).

Avoid repetition of information (to prevent anomalies).

Minimize NULL values, as they can be ambiguous.


Ensure proper join specifications to avoid spurious tuples.

Anomalies to Avoid:

1. Insertion Anomaly:

Inability to add data without depending on other data.

Example: Can’t add a project without an assigned employee.

2. Deletion Anomaly:

Removing a record could delete critical information.

Example: Deleting an employee could remove project details.

3. Modification Anomaly:

Updating one instance requires multiple changes.

Example: Changing a project’s budget affects multiple rows.


4. Functional Dependencies (FDs)

A functional dependency (FD) describes relationships between attributes.

Definition:

A set of attributes X functionally determines Y (denoted X → Y) if:

The value of X uniquely determines the value of Y.

Example: EmployeeID → EmployeeName

Examples of FDs:

(EmployeeID, ProjectID) → (EmployeeName, Title, Salary)

EmployeeID → (EmployeeName, Title, Salary)

ProjectID → (ProjectName, Budget)


Title → Salary

Armstrong’s Axioms (FD Inference Rules):

1. Reflexivity: If Y ⊆ X, then X → Y

2. Augmentation: If X → Y, then XZ → YZ

3. Transitivity: If X → Y and Y → Z, then X → Z

Additional Inference Rules:

Decomposition: If X → YZ, then X → Y and X → Z

Union: If X → Y and X → Z, then X → YZ

Pseudotransitivity: If X → Y and WY → Z, then WX → Z


4. Normal Forms

Normalization aims to achieve various levels of organization called Normal


Forms (NF). Each normal form addresses specific types of redundancy and
anomalies.

First Normal Form (1NF)

Criteria:

All attributes contain atomic (indivisible) values.

No repeating groups or nested relations.

Example Violation:

An attribute storing multiple phone numbers.

Solution:

Create separate rows for each phone number.


Second Normal Form (2NF)

Criteria:

Relation is in 1NF.

No partial dependency, meaning every non-prime attribute must depend on


the whole primary key.

Example Violation:

If the primary key is (StudentID, CourseID) and StudentName depends only


on StudentID, this is a partial dependency.

Solution:

Decompose into separate tables: STUDENT (StudentID, StudentName) and


ENROLLMENT (StudentID, CourseID, Grade)

Third Normal Form (3NF)

Criteria:
Relation is in 2NF.

No transitive dependencies, meaning non-prime attributes must depend only


on the primary key, not on other non-key attributes.

Example Violation:

If EmployeeID → Title and Title → Salary, the dependency is transitive.

Solution:

Decompose the relation into separate tables:

EMPLOYEE (EmployeeID, Title) and TITLE_SALARY (Title, Salary)

Boyce-Codd Normal Form (BCNF)

Criteria:

Relation is in 3NF.

Every determinant is a candidate key.


Example Violation:

If ProjectLocation → ProjectID and ProjectID is not a superkey.

Solution:

Decompose into PROJECT (ProjectID, ProjectName) and LOCATION


(ProjectLocation, ProjectID)

5. Decomposition Process

Normalization involves decomposing tables while ensuring:

1. Lossless decomposition: No loss of information when tables are joined.

2. Dependency preservation: Ensure original dependencies are


maintained.
6. Example of Normalization Process

Given the relation:

STUDENT (Student#, Module#, S_name, Age, Address, M_title, Inst_code,


Inst_name, Sem, Grade)

With the functional dependencies:

1. Student# → S_name, Age, Address

2. Module# → M_title, Inst_code

3. Inst_code → Inst_name

4. Student#, Module# → Grade

Step 1: Convert to 1NF (Atomic values only):

Separate multi-valued attributes into new relations.

Step 2: Convert to 2NF (Eliminate partial dependencies):

Relations:
STUDENT (Student#, S_name, Age)

ADDRESS (Student#, Zip, St.#, City)

MODULE (Module#, M_title, Inst_code, Inst_name, Sem)

STUDY (Student#, Module#, Grade)

Step 3: Convert to 3NF (Eliminate transitive dependencies):

Relations:

STUDENT (Student#, S_name, Age)

ADDRESS (Student#, Zip, St.#, City)

MODULE (Module#, M_title, Inst_code, Sem)

STUDY (Student#, Module#, Grade)

7. Practical Study Tips

1. Understand Functional Dependencies:


Practice identifying FDs from sample data.

2. Master Anomalies:

Be able to explain how normalization fixes them.

3. Solve Normalization Exercises:

Practice converting relations to 1NF, 2NF, 3NF, and BCNF.

4. Revise Armstrong’s Axioms:

Reflexivity, Augmentation, and Transitivity rules are commonly tested.

5. Work on Real-World Scenarios:

Try normalizing datasets from your course projects or sample business cases.
Would you like a quiz or practice exercises to test your understanding?

Ch 6

Here is a comprehensive breakdown of the “From ERD to Relational Mapping”


document to help you study for your exam efficiently.

1. ER-to-Relational Mapping Overview

The process of converting an Entity-Relationship Diagram (ERD) into a


Relational Model, ensuring that all data relationships are preserved for
database implementation.

Key Steps in ER-to-Relational Mapping:

1. Mapping Regular Entity Types

2. Mapping Weak Entity Types

3. Mapping Binary 1:1 Relationships


4. Mapping Binary 1:N Relationships

5. Mapping Binary M:N Relationships

6. Mapping Multivalued Attributes

7. Mapping N-ary Relationship Types

8. Mapping Specialization/Generalization (EER Model Constructs)

2. ER-to-Relational Mapping Steps

Step 1: Mapping Regular (Strong) Entity Types

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

All simple attributes of the entity become columns in the table.


One attribute (or a composite key) is selected as the Primary Key.

Example:

Entity: EMPLOYEE(SSN, Name, Address, DOB)

Mapped to: EMPLOYEE(SSN PRIMARY KEY, Name, Address, DOB)

Step 2: Mapping Weak Entity Types

A weak entity depends on a strong entity.

Create a table for the weak entity.

Include the weak entity’s simple attributes.

Add the primary key of the owner entity as a foreign key.

The primary key is a combination of the foreign key and the weak entity’s
partial key.

Example:

Entity: DEPENDENT(Dependent_Name, Relationship)

Owner: EMPLOYEE(SSN)
Mapped to: DEPENDENT(ESSN FOREIGN KEY, Dependent_Name PRIMARY
KEY, Relationship)

Step 3: Mapping Binary 1:1 Relationship Types

Possible approaches:

1. Foreign Key Approach (add one entity’s key as a foreign key to


another).

2. Merged Relation (combine both entities and their relationship in a


single table).

3. Relationship Relation (create a separate table for the relationship).

Example:

Relationship: MANAGES(Employee, Department)

Mapped to:

Foreign key approach: DEPARTMENT(MGRSSN FOREIGN KEY →


EMPLOYEE.SSN)
Merged approach: Combine EMPLOYEE and DEPARTMENT tables.

Step 4: Mapping Binary 1:N Relationship Types

Add the primary key of the “1” side as a foreign key in the “N” side table.

Include relationship attributes in the table representing the “N” side.

Example:

Relationship: WORKS_FOR(Employee, Department)

Mapped to: EMPLOYEE(DNO FOREIGN KEY → DEPARTMENT.DNUMBER)

Step 5: Mapping Binary M:N Relationship Types

Create a separate table to represent the relationship.

Include foreign keys from both participating entities.

The combination of these foreign keys forms the primary key.

Add relationship attributes if needed.


Example:

Relationship: WORKS_ON(Employee, Project, Hours)

Mapped to:

WORKS_ON(

ESSN FOREIGN KEY → EMPLOYEE.SSN,

PNO FOREIGN KEY → PROJECT.PNUMBER,

Hours,

PRIMARY KEY(ESSN, PNO)

Step 6: Mapping Multivalued Attributes

Create a new relation for the multivalued attribute.

Include the primary key of the entity that owns the attribute as a foreign key.

The combination of the attribute and foreign key forms the primary key.

Example:

Attribute: DEPARTMENT(LOCATIONS)

Mapped to:
DEPT_LOCATIONS(

DNUMBER FOREIGN KEY → DEPARTMENT.DNUMBER,

DLOCATION PRIMARY KEY

Step 7: Mapping N-ary Relationship Types (n > 2 entities)

Create a new relation for the N-ary relationship.

Include foreign keys for all participating entities.

Use a combination of all foreign keys as the primary key.

Example:

Relationship: SUPPLY(Supplier, Part, Project, Quantity)

Mapped to:

SUPPLY(

SNAME FOREIGN KEY → SUPPLIER,

PARTNO FOREIGN KEY → PART,

PROJNAME FOREIGN KEY → PROJECT,

Quantity,

PRIMARY KEY(SNAME, PARTNO, PROJNAME)


)

4. Mapping Enhanced ER (EER) Model Constructs

Step 8: Specialization and Generalization

Specialization divides a general entity into specialized entities, whereas


generalization combines multiple entities into a generalized entity.

Options for Mapping Specialization/Generalization:

1. Option 8A: Superclass-Subclass Mapping (Multiple Tables)

Create a table for the superclass.

Create separate tables for each subclass, containing the primary key of the
superclass.

Works for both total and partial specialization.

2. Option 8B: Subclass Relations Only

Create tables for only the specialized subclasses.


Works when specialization is total (each entity belongs to at least one
subclass).

3. Option 8C: Single Table with Type Attribute

Create one table with an additional attribute to identify the subclass type.

4. Option 8D: Single Table with Boolean Flags

Create one table with multiple boolean attributes indicating subclass


membership.

Example:

Superclass: VEHICLE(VehicleID, Make, Model)

Subclasses: CAR(VehicleID, SeatingCapacity) and TRUCK(VehicleID,


PayloadCapacity)

5. Summary of ER to Relational Mapping Correspondence


6. Mapping Shared Subclasses (Multiple Inheritance)

If an entity belongs to multiple superclasses, it must inherit the primary key


from all.

Use any of the four mapping options, ensuring compatibility across


superclasses.

Example:

Shared subclass STUDENT_ASSISTANT, inheriting from both STUDENT and


EMPLOYEE.

7. Mapping Practice Exercise

ER Schema Example:

A ship-tracking database containing entities such as ships, ports, and


tracking events.

Mapping Steps:

1. Identify regular and weak entities.


2. Determine relationship cardinalities (1:1, 1:N, M:N).

3. Apply the mapping rules to convert entities and relationships into


relations.

8. Exam Preparation Tips

1. Understand Relationship Types:

Be clear on differences between 1:1, 1:N, and M:N mappings.

2. Practice Mapping Exercises:

Work on converting ER diagrams into relational tables.

3. Memorize Mapping Options:


Understand the different ways to map specialization and generalization.

4. Focus on Foreign Key Placement:

Ensure proper placement of foreign keys to maintain referential integrity.

Would you like further explanation on specific concepts or additional


exercises?

Ch 5

Here’s a detailed summary of the Relational Model document to help you


study for your exam effectively.

1. Introduction to the Relational Model

Proposed by E.F. Codd in 1970, revolutionizing database management.

Based on mathematical principles of set theory and first-order logic.


Provides a strong foundation for data management by organizing data into
relations (tables).

2. Key Concepts in the Relational Model

Informal Definitions:

Relation ≈ Table (A two-dimensional structure of rows and columns).

Attribute ≈ Column Name (A named property of an entity).

Tuple ≈ Row (A single record in a relation).

Domain ≈ Set of Values (Allowed values for an attribute).

Relation Schema ≈ Structure of the table (Defines attributes and their


domains).

Relation Instance ≈ Actual data (Collection of tuples at a given time).

Example Table:

| Student | Course | Grade | |---------|---------|-------| | Harry | Database| A |


| Hermione| Database| A- | | Ron | Database| C |
Formal Definitions:

A relation schema R(A1, A2, …, An) consists of:

Relation name: R

Attributes: A1, A2, …, An

Domain of values for each attribute.

Example: CUSTOMER(CustID, CustName, Address, Phone#)

A tuple (row) consists of an ordered set of values:

Example: <632895, “John Smith”, “101 Main St”, “(404) 123-4567”>

Characteristics of Relations:

1. Ordering of Tuples:
No specific order (rows are unordered in a relation).

2. Ordering of Attributes:

Attributes have a defined sequence in the schema.

3. Atomicity:

Values must be atomic (indivisible).

4. Uniqueness:

Each tuple is unique.

5. Domain Constraint:

Values must belong to a specified domain.


3. Relational Model Constraints

Constraints ensure data consistency and integrity.

Types of Constraints:

1. Key Constraints:

Ensure uniqueness and proper identification of tuples.

2. Entity Integrity:

The primary key of a relation cannot be NULL.

Example: Every EmployeeID in the EMPLOYEE table must have a value.

3. Referential Integrity:
Ensures valid relationships between tables using foreign keys.

Example: DeptNo in EMPLOYEE must match a valid department in


DEPARTMENT.

4. Semantic Integrity:

Business rules that cannot be expressed directly in the relational model (e.g.,
“an employee cannot work more than 40 hours per week”).

Key Constraints:

1. Super Key:

A set of attributes that uniquely identifies a tuple.

Example: {SSN, Name} or {SSN}


2. Candidate Key:

A minimal super key (removing any attribute makes it non-unique).

Example: {SSN}

3. Primary Key (PK):

The selected candidate key that uniquely identifies each record.

4. Foreign Key (FK):

An attribute in one relation that refers to the primary key of another relation.

Example: DeptNo in EMPLOYEE referencing DEPARTMENT.

5. Relational Integrity Rules


1. Entity Integrity Rule:

No primary key attribute can be NULL.

Ensures each record is uniquely identifiable.

2. Referential Integrity Rule:

A foreign key must refer to an existing primary key in the referenced table or
be NULL.

Example:

| EmployeeID | Name | DeptNo |

| 101 | Alice | 10 |

| 102 | Bob | NULL |

3. Domain Constraints:

Ensures attribute values fall within the specified domain (e.g., age should be
positive integers).
4. Relational Model Operations

Operations are divided into two categories:

1. Retrieval Operations:

Used to query data from the database.

Examples: SELECT, PROJECT, JOIN

2. Update Operations:

Used to modify data in the database.

Operations include:

Insert: Add new tuples.

Delete: Remove tuples.

Update: Modify existing tuples.


Considerations in Updates:

All updates must preserve integrity constraints.

Deletions or modifications may propagate changes across related tables.

5. Violating Integrity Constraints

Examples of violations include:

1. Key Constraint Violation:

Trying to insert a duplicate primary key value.

2. Entity Integrity Violation:

Inserting a NULL value into a primary key.


3. Referential Integrity Violation:

Deleting a referenced tuple without handling dependencies.

Handling Violations:

Rejecting the operation.

Cascading the changes to dependent tables.

Setting NULL values.

6. Relational Model Examples and Exercises

Example 1: Key Constraints

Consider the following STUDENT table:

Super Key: {StudentID, Course}


Candidate Key: {StudentID}

Primary Key: {StudentID}

Foreign Key Example: Course could reference a COURSE table.

Exercise: Identify primary keys and foreign keys in a BOOKS table.

7. Exam Preparation Tips

1. Understand Relational Concepts:

Definitions of relation, tuple, attribute, and domain.

2. Memorize Constraints:

Know the rules for primary keys, foreign keys, and referential integrity.

3. Practice Operations:
Writing queries to retrieve and manipulate data.

4. Recognize Violations:

Identify when integrity constraints are violated and how to resolve them.

5. Work on Sample Tables:

Practice defining schemas and enforcing constraints.

Ch 4

Here’s a detailed summary of the Enhanced Entity-Relationship (EER) Model


document to help you study for your exam efficiently.

1. Overview of Enhanced Entity-Relationship Model (EERD)

The Enhanced Entity-Relationship (EER) Model extends the traditional Entity-


Relationship (ER) Model by introducing additional concepts to model complex
relationships more accurately.

Key EER Concepts:


Subclasses and Superclasses

Specialization and Generalization

Categories (Union Types)

Attribute and Relationship Inheritance

Shared Subclasses (Multiple Inheritance)

EER includes some object-oriented concepts such as inheritance, allowing


better representation of real-world scenarios.

2. Subclasses and Superclasses

Definition:

An entity type can have meaningful sub-groupings called subclasses.

The general entity type is called the superclass, and its sub-groupings are
subclasses.

Example:
EMPLOYEE can have subclasses like:

SECRETARY, ENGINEER, TECHNICIAN (based on job type)

SALARIED_EMPLOYEE, HOURLY_EMPLOYEE (based on payment method)

Key Characteristics:

IS-A Relationships:

SECRETARY IS-A EMPLOYEE

ENGINEER IS-A EMPLOYEE

Inheritance:

Subclasses inherit attributes and relationships from the superclass.

Example: EMPLOYEE(Name, SSN, Address), inherited by SECRETARY.

Rules:

1. An entity must exist in the superclass to be part of a subclass.


2. An entity can belong to multiple subclasses.

3. Specialization

Definition:

Specialization is the process of creating subclasses from a superclass based


on specific characteristics.

Examples:

EMPLOYEE specialized into ENGINEER, TECHNICIAN, SECRETARY (based on


job role).

EMPLOYEE specialized into SALARIED_EMPLOYEE, HOURLY_EMPLOYEE (based


on salary type).

Specialization Characteristics:

Specific Attributes:
Subclasses can have their own unique attributes (e.g., TypingSpeed for
SECRETARY).

Participation in Relationships:

Subclasses can have relationships not applicable to the superclass.

Notation in EER Diagrams:

Specialization is depicted by a hollow triangle pointing to the superclass.

4. Generalization

Definition:

Generalization is the reverse of specialization, where common attributes of


several entities are abstracted into a higher-level superclass.

Example:

CAR and TRUCK can be generalized into VEHICLE.


Key Features:

Combines multiple entity types into a higher-level superclass.

Captures shared attributes and relationships in the superclass.

Notation in EER Diagrams:

A hollow triangle pointing from the subclass to the generalized superclass.

5. Attribute Inheritance

In an EER model, subclasses inherit:

1. All attributes of the superclass.

2. All relationships of the superclass.

Example:
If EMPLOYEE has attributes {Name, SSN, Address}, its subclass SECRETARY
will inherit these attributes along with any additional attributes like
{TypingSpeed}.

6. Constraints in Specialization and Generalization

Types of Constraints:

1. Disjointness Constraint (d/o notation):

Specifies whether an entity can belong to multiple subclasses.

Disjoint (d): An entity can belong to only one subclass.

Overlapping (o): An entity can belong to multiple subclasses.

2. Completeness Constraint (Total vs. Partial):

Total Specialization: Every entity in the superclass must belong to a subclass.


(Depicted with a double line in EERD)

Partial Specialization: Some entities may not belong to any subclass.


(Depicted with a single line in EERD)
Examples:

Disjoint, Total: An EMPLOYEE must be either ENGINEER or SECRETARY, not


both.

Overlapping, Partial: A STUDENT can also be a TEACHING_ASSISTANT without


being required to.

7. Categories (Union Types)

Definition:

Categories allow an entity to be a member of multiple parent classes,


representing a union of entity sets.

Example:

An entity PART_TIME_EMPLOYEE may be associated with either STUDENT or


FACULTY.

Characteristics:
Can have overlapping attributes from multiple entities.

Represented in diagrams by a U symbol.

8. Specialization and Generalization Hierarchies & Lattices

Hierarchy (Single Inheritance):

Each subclass has only one direct superclass.

Forms a tree-like structure.

Lattice (Multiple Inheritance):

A subclass can have multiple superclasses (shared subclass).

Forms a directed graph.

Example of Shared Subclass:

An ENGINEERING_MANAGER is both an ENGINEER and a MANAGER.


9. Differences Between Specialization and Generalization

10. Practical EERD Diagram Notations

UML Class Diagrams:

Some database modeling tools represent EER diagrams using UML notation.

Classes represent entities, and generalization is shown using arrows.

Example:

UML notation for EMPLOYEE and its subclasses using inheritance arrows.

11. Exam Preparation Tips

1. Understand Key Concepts:

Subclass, superclass, specialization, generalization, inheritance.


2. Practice EERD Notation:

Draw EER diagrams for real-world scenarios (e.g., school, hospital).

3. Differentiate Constraints:

Disjoint vs. Overlapping, Total vs. Partial.

4. Work on Example Problems:

Convert an ER model to an EERD and vice versa.

5. Compare Specialization and Generalization:

Identify scenarios where either would be applicable.


Would you like further clarification on any of the topics or additional
exercises to practice?

Would you like more practice questions or examples to test your


understanding?

Ch 3

Here’s a detailed summary of the Entity-Relationship Diagram (ERD)


document to help you study for your exam effectively.

1. Database Development Life Cycle (DDLC)

Phases of the Database Life Cycle:

1. System Definition:

Identify database application scope and users.


Critical phase in defining project goals.

2. Database Design:

Develop a conceptual schema (ERD) independent of DBMS.

Map conceptual schema to a physical design.

3. Database Implementation:

Create database structure and software applications.

4. Data Loading and Conversion:

Populate the database with data.

5. Application Conversion:
Adapt applications to the new database system.

6. Testing and Validation:

Ensure data accuracy and system reliability.

7. Operation:

Run the system in production.

8. Monitoring and Maintenance:

Performance optimization and troubleshooting.

2. Entity-Relationship (ER) Model Overview


The ER model describes data in terms of:

Entities (things or objects)

Attributes (properties of entities)

Relationships (associations between entities)

Key Characteristics:

Provides a conceptual view of the database.

Independent of specific DBMS platforms.

Helps identify design issues early.

3. ER Model Components

Entities:

Represents real-world objects.


Examples:

Person: STUDENT, EMPLOYEE

Place: UNIVERSITY, DEPARTMENT

Object: BUILDING, MACHINE

Event: SALE, EXAM

Concept: COURSE, ACCOUNT

Entity Representation:

Rectangles represent entities in ER diagrams.

Attributes:

Properties that describe an entity.

Example: STUDENT (ID, Name, DoB)


Types of Attributes:

1. Simple Attributes:

Atomic values (e.g., ID, DoB).

2. Composite Attributes:

Can be divided into sub-components.

Example: Address → (Street, City, Zip).

3. Single-Valued Attributes:

One value per entity instance.

Example: Age.

4. Multivalued Attributes:
Multiple values for an entity.

Example: {PhoneNumbers}.

5. Derived Attributes:

Values calculated from other attributes.

Example: Age derived from Date of Birth.

Notation:

Ovals represent attributes.

Double ovals indicate multivalued attributes.

Key Attributes:

Uniquely identify an entity.


Example: Employee(SSN) where SSN is the key.

Types of Keys:

1. Primary Key:

Unique identifier for an entity.

2. Composite Key:

Combination of multiple attributes to form a unique key.

Notation:

Underlined attributes indicate primary keys.

3. Relationships in ER Model
A relationship connects two or more entities with specific meaning.

Examples:

An EMPLOYEE works on a PROJECT.

A STUDENT enrolls in a COURSE.

Types of Relationships (Based on Degree):

1. Unary (Recursive) Relationship:

A relationship between instances of the same entity.

Example: An employee supervises another employee.

2. Binary Relationship (Most Common):

Relationship between two entity types.

Example: EMPLOYEE works in DEPARTMENT.


3. Ternary Relationship:

Involves three entity types.

Example: SUPPLIER supplies PART to PROJECT.

Notation:

Diamonds represent relationships.

Lines connect entities to relationships.

4. Relationship Constraints

Cardinality Ratios:

Defines the number of entity instances associated with another entity.

One-to-One (1:1): Each entity in A relates to one entity in B.


Example: Each department has one manager.

One-to-Many (1:N): An entity in A relates to multiple entities in B.

Example: A department has many employees.

Many-to-Many (M:N): Many entities in A relate to many entities in B.

Example: Employees work on multiple projects.

Notation:

Numbers (1, N, M) near relationship lines indicate cardinality.

Participation Constraints:

Defines the minimum number of times an entity participates in a


relationship.

1. Total Participation (Double Line):


Every entity in the set participates in at least one relationship.

Example: Every employee must work for a department.

2. Partial Participation (Single Line):

Some entities may not participate in any relationship.

Example: Some employees may not manage any department.

5. Weak Entity Types

Entities that do not have a key attribute of their own.

Depend on a strong entity (owner).

Identified by a partial key, which is unique within the weak entity.


Example:

DEPENDENT entity depends on EMPLOYEE.

Notation:

Weak entities are shown with double rectangles.

Identifying relationships are shown with double diamonds.

6. Attributes in Relationship Types

Relationships can have attributes to capture additional details.

Example: The WORKS_ON relationship may have an attribute HoursWorked.

Key Points:

1:1 relationships can migrate attributes to either side.

1:N relationships migrate attributes to the “many” side.


M:N relationships require a separate relation for attributes.

7. ER Diagram Notations Summary

8. Design Guidelines for ER Modeling

1. Proper Naming:

Entities: Singular, uppercase.

Relationships: Uppercase verbs.

Attributes: Capitalized.

2. Avoid Redundancy:

Minimize data duplication.


3. Refinement Process:

Convert attributes into relationships if necessary.

4. Generalization and Specialization:

Abstract common features into higher-level entities.

9. UML Alternative Notation

ER models can also be represented using UML class diagrams, which include:

Classes (Entities)

Attributes (Properties)

Associations (Relationships)
10. Exam Preparation Tips

1. Understand Core Concepts:

Focus on entity types, relationships, and constraints.

2. Memorize ER Diagram Symbols:

Practice drawing ER diagrams with proper notations.

3. Practice Problem Solving:

Convert business scenarios into ER models.

4. Identify Key and Weak Entities:

Ensure primary and foreign keys are correctly assigned.


Would you like additional exercises to test your understanding?

Ch2

Here’s a detailed summary of the Database System Concepts document to


help you study for your exam efficiently.

1. Brief History of Database Models

Early Database Models:

1. Hierarchical Model (1960s–1970s):

Data organized in a tree structure (parent-child relationships).

Each child has only one parent (1-to-many relationships).

Example: DEPARTMENT → EMPLOYEE → PROJECT.

2. Network Model:
Supports many-to-many relationships.

Data represented using owner-member relationships.

More flexible than the hierarchical model.

Modern Database Models:

3. Relational Model (1970s–1980s):

Introduced by E.F. Codd in 1970.

Organizes data in tables (rows and columns).

Easier to query using SQL.

4. Object-Oriented Databases (OODBMS) (1990s):

Stores complex data as objects.

Supports inheritance and encapsulation.


5. Object-Relational Databases:

Combines relational and object-oriented features.

6. Web and E-commerce Databases:

XML and JSON-based data storage for web applications.

2. Data Models

A data model is a set of concepts used to describe data structure,


relationships, and constraints.

Types of Data Models:

1. Conceptual Data Model:


High-level representation (e.g., ER diagrams).

Focuses on business entities and relationships.

Independent of database technology.

2. Logical Data Model:

Translates conceptual schema into a DBMS-compatible form.

Includes tables, attributes, keys, and relationships.

3. Physical Data Model:

Describes how data is stored on disk.

Focuses on performance and storage optimization.


4. Schema vs. Instance

Schema:

Defines the structure of the database (e.g., table design).

Changes infrequently.

Instance (State):

The actual data in the database at a specific moment.

Changes frequently as data is inserted or modified.

Example:

Schema: STUDENT (StudentID, Name, Address)

Instance:

(101, ‘Alice’, ‘NY’)

(102, ‘Bob’, ‘LA’)

5. Three-Schema Architecture
This architecture separates the database into three layers to provide data
abstraction and independence.

1. Internal Schema (Physical Level):

Describes how data is stored on disk (storage structure, indexing).

2. Conceptual Schema (Logical Level):

Describes the entire database structure (tables, constraints).

3. External Schema (View Level):

Describes specific views tailored to different users.

Advantages:

Provides data abstraction and independence.


Users interact with external views without worrying about physical storage.

4. Data Independence

1. Logical Data Independence:

Ability to change the conceptual schema without affecting external schemas.

2. Physical Data Independence:

Ability to change the internal schema without affecting the conceptual


schema.

Example:

Changing the storage format (e.g., changing from file storage to indexed
storage) without affecting application queries.

5. Database Management System (DBMS) Languages


DBMS uses different types of languages for data manipulation and
management.

Types of DBMS Languages:

1. Data Definition Language (DDL):

Used to define database structure (tables, indexes, constraints).

Example:

CREATE TABLE STUDENT (

StudentID INT PRIMARY KEY,

Name VARCHAR(50)

);

2. Data Manipulation Language (DML):

Used to retrieve and manipulate data.

Example:

SELECT * FROM STUDENT WHERE Name = ‘Alice’;


3. View Definition Language (VDL):

Defines external views of the database.

Key Functions of a DBMS:

Data storage and retrieval.

Security and access control.

Concurrency control.

Backup and recovery.

6. Database System Architectures

Types of Database Architectures:

1. Centralized Architecture:
All data is stored and processed on a single server.

2. Distributed Architecture:

Data is distributed across multiple servers.

Ensures high availability and scalability.

3. Client-Server Architecture:

The client requests data, and the server processes the request.

Example: Web applications using MySQL.

7. Advantages of Database Systems

1. Data Redundancy Control:


Centralized control avoids data duplication.

2. Data Integrity and Consistency:

Ensures accurate and consistent data through constraints.

3. Security and Access Control:

Restrict access to authorized users.

4. Backup and Recovery:

Provides mechanisms to recover data in case of failures.

5. Multi-User Access:

Supports concurrent access without conflicts.


8. Summary of Key Concepts

9. Exam Preparation Tips

1. Understand Different Database Models:

Compare hierarchical, network, and relational models.

2. Memorize the Three-Schema Architecture:

Identify the role of each schema level.

3. Practice SQL Queries:

Learn basic DDL and DML commands.


4. Know Data Independence:

Explain the differences between logical and physical independence.

5. Review Database Design Concepts:

ER modeling, schema vs. instance, normalization.

Would you like additional exercises or explanations on any specific topics?

Ch 1

Here’s a detailed summary of the Database Systems Introduction document


to help you study effectively for your exam.

1. Module Information
Instructor: Dr. Doaa Elzanfaly

Office Hours: Room H210

Textbook:

“Fundamentals of Database Systems” by El Masri & Navathe (7 th Edition)

“Database Systems: A Practical Approach” by Connolly & Begg (4 th Edition)

2. Assessment Scheme

Project: 50%

Project Deliverables:

Week 3: Proposal

Week 6: Database Identification & Design (40%)

Week 11: Implementation & Final Report (50%)

Week 12: Presentation (10%)


Final Exam: 50%

Bonus Points: 5% based on participation.

3. Module Objectives

1. Understand fundamental concepts of databases.

2. Develop database systems using appropriate tools.

3. Use SQL to manipulate relational databases.

4. Address key database management challenges.


5. Why Study Databases?

Databases are essential for:

Storing: Managing large amounts of structured data.

Understanding: Through data models and schema.

Securing: Implementing access controls and backups.

Retrieving: Using query languages (SQL).

6. Topics Covered

Lectures:

1. Database Concepts

2. Data Modeling (ER Model, EERD)

3. Relational Data Model


4. Mapping ERD to Relational Schema

5. Relational Algebra

6. Normalization

7. Database Management Issues

Lab:

Implementing databases using MS SQL Server.

Developing and manipulating tables.

Understanding data types and constraints.

7. Basic Definitions
1. Data:

Known facts that can be recorded.

2. Database:

Collection of related data organized for easy retrieval.

3. Database Management System (DBMS):

Software that enables the creation, maintenance, and retrieval of data.

4. Database System:

The combination of the DBMS and the data.


8. Typical DBMS Functionalities

1. Defining a Database:

Define tables, data types, and constraints.

2. Constructing a Database:

Load data into storage.

3. Manipulating Data:

Querying, inserting, updating, deleting.

4. Concurrent Access:

Multi-user support while maintaining consistency.


9. Files vs. DBMS

10. Characteristics of the Database Approach

1. Data Abstraction:

Presents a conceptual view of the data, hiding storage details.

2. Program-Data Independence:

Allows changes in storage structure without affecting programs.

3. Self-Describing Nature:

Stores metadata (data about data) within the database.

4. Multi-User Access:
Provides concurrent access to multiple users with consistency.

11. Database System Environment

Components:

Hardware

Software (DBMS)

Data

Procedures

Users

12. Types of Database Users


1. Database Administrators (DBAs):

Manage security, backups, and performance tuning.

2. Database Designers:

Design database schemas and constraints.

3. End Users:

Use the database for queries and reports.

13. Major Commercial Database Systems

Oracle (8i, 9i, etc.):

World’s 3rd largest software company.


IBM DB2:

Used in enterprise systems.

Microsoft SQL Server:

Popular for business applications.

MySQL & PostgreSQL:

Popular open-source databases.

14. When Not to Use a DBMS

Considerations:

1. Cost:

High initial investment and additional hardware.


2. Overhead:

Increased complexity for simple applications.

3. Special Cases:

Some applications may not need multi-user capabilities.

Scenarios Where DBMS May Not Be Needed:

Simple, well-defined applications.

Low volume of data with minimal changes.

15. Exam Preparation Tips


1. Understand Core Concepts:

Study DBMS functions and characteristics.

2. Learn SQL Basics:

Practice creating and manipulating tables in SQL.

3. Differentiate File vs. Database Approaches:

Compare their advantages and disadvantages.

4. Revise Database Design Concepts:

Focus on ER modeling and normalization.


Would you like more details or exercises for practice?

Here is a comprehensive quiz based on the eight documents covering


various database concepts. Each question includes an answer and an
explanation to help reinforce your understanding.

Database Systems Quiz

Section 1: Basic Concepts

1. Which of the following is NOT a key feature of a database management


system (DBMS)?

a) Data Redundancy Control

b) Data Encryption

c) Manual Data Storage

d) Multi-User Access

Answer: c) Manual Data Storage

Explanation: A DBMS automates data storage, retrieval, and management,


whereas manual storage refers to traditional file-based systems.

2. What is the primary function of the conceptual schema in the three-


schema architecture?
a) Defines the physical storage of data

b) Provides user-specific views of data

c) Describes the overall structure of the database

d) Maps internal schema to physical storage

Answer: c) Describes the overall structure of the database

Explanation: The conceptual schema defines the logical structure of the


entire database, independent of physical storage or user views.

3. What is the key advantage of program-data independence in a DBMS?

a) Faster data processing

b) Ability to change data structures without modifying application programs

c) Increased storage capacity

d) Improved data security

Answer: b) Ability to change data structures without modifying application


programs

Explanation: Program-data independence allows schema changes without


requiring changes to the programs that access the data.

Section 2: Relational Model

4. In the relational model, what term is used to describe a row in a table?

a) Attribute
b) Domain

c) Tuple

d) Schema

Answer: c) Tuple

Explanation: A tuple is a single row in a relation (table), representing a


unique record.

5. Which of the following is a valid relational integrity constraint?

a) Foreign Key Constraint

b) Multi-Valued Dependency

c) Trigger Constraint

d) Check Constraint

Answer: a) Foreign Key Constraint

Explanation: A foreign key constraint ensures referential integrity by linking


tables through primary key references.

6. What does the term ‘degree’ of a relation refer to in the relational model?

a) Number of tuples

b) Number of attributes

c) Number of relationships

d) Number of foreign keys


Answer: b) Number of attributes

Explanation: The degree of a relation refers to the number of attributes


(columns) in a table.

Section 3: ER and EER Models

7. In an ER diagram, which symbol is used to represent a relationship?

a) Rectangle

b) Diamond

c) Oval

d) Double line

Answer: b) Diamond

Explanation: Relationships between entities are represented using diamonds


in ER diagrams.

8. What is the purpose of specialization in the Enhanced ER (EER) model?

a) To merge multiple entity types into one

b) To define subclass entities with additional attributes

c) To ensure data integrity

d) To minimize data redundancy


Answer: b) To define subclass entities with additional attributes

Explanation: Specialization creates more specific sub-entities from a general


superclass based on distinguishing characteristics.

9. A weak entity set requires which type of relationship with its owner entity?

a) Ternary

b) Binary

c) Identifying

d) Aggregation

Answer: c) Identifying

Explanation: A weak entity relies on a strong entity and is linked via an


identifying relationship with a composite key.

Section 4: Normalization

10. What is the primary goal of database normalization?

a) To increase query performance

b) To eliminate redundancy and avoid anomalies

c) To allow multi-user access

d) To enhance data visualization

Answer: b) To eliminate redundancy and avoid anomalies


Explanation: Normalization structures a database to reduce redundancy and
improve data integrity.

11. Which normal form removes partial dependencies?

a) 1NF

b) 2NF

c) 3NF

d) BCNF

Answer: b) 2NF

Explanation: 2NF ensures that all non-key attributes depend on the entire
primary key, not just part of it.

12. If a relation is in 3NF but not in BCNF, what issue may still exist?

a) Partial dependency

b) Transitive dependency

c) Functional dependency

d) Redundant dependency

Answer: c) Functional dependency

Explanation: BCNF eliminates functional dependencies where a non-key


attribute determines another attribute.
Section 5: SQL and Operations

13. What SQL command is used to remove all records from a table without
deleting the table structure?

a) DELETE

b) DROP

c) TRUNCATE

d) ALTER

Answer: c) TRUNCATE

Explanation: The TRUNCATE command removes all records but retains the
table structure.

14. Which SQL clause is used to filter records based on conditions?

a) GROUP BY

b) WHERE

c) ORDER BY

d) HAVING

Answer: b) WHERE

Explanation: The WHERE clause filters records based on specified conditions.


15. In SQL, which of the following constraints ensures that a column cannot
have NULL values?

a) UNIQUE

b) PRIMARY KEY

c) NOT NULL

d) CHECK

Answer: c) NOT NULL

Explanation: The NOT NULL constraint ensures a column must contain a


value.

Section 6: Transactions and Constraints

16. Which property ensures that a transaction is executed completely or not


at all?

a) Isolation

b) Durability

c) Atomicity

d) Consistency

Answer: c) Atomicity

Explanation: Atomicity guarantees that all operations within a transaction are


completed successfully or none at all.
17. Which SQL command is used to enforce referential integrity by linking
tables?

a) CHECK

b) FOREIGN KEY

c) PRIMARY KEY

d) DEFAULT

Answer: b) FOREIGN KEY

Explanation: FOREIGN KEY enforces referential integrity by ensuring


relationships between tables are valid.

Section 7: Database Design Considerations

18. Which of the following is a disadvantage of using a database


management system (DBMS)?

a) Improved data sharing

b) High implementation cost

c) Reduced redundancy

d) Easier maintenance

Answer: b) High implementation cost

Explanation: DBMS systems require significant resources for setup,


maintenance, and hardware.
19. In database design, which approach is typically used when migrating
from an ERD to a relational schema?

a) Top-down approach

b) Bottom-up approach

c) Hybrid approach

d) Functional approach

Answer: a) Top-down approach

Explanation: The top-down approach starts from high-level ER models and


converts them into relational schema.

20. Which of the following is NOT a component of a database system?

a) Hardware

b) Users

c) Operating System

d) Software

Answer: c) Operating System

Explanation: The database system consists of hardware, software, data,


users, and procedures but does not include the OS itself.

Would you like additional practice questions or explanations on any topics?


Here is a practical quiz focusing on real-world scenarios, SQL queries,
relational diagrams, and problem-solving exercises.

Practical Database Systems Quiz

Section 1: SQL Queries

1. Given the following STUDENT table:

Which SQL query retrieves students majoring in ‘CS’?

a) SELECT StudentID, Name FROM STUDENT WHERE Age > 20;

b) SELECT * FROM STUDENT WHERE Major = ‘CS’;

c) SELECT StudentID, Major FROM STUDENT WHERE Major = ‘IT’;

d) SELECT ALL FROM STUDENT WHERE Major = ‘CS’;

Answer: b) SELECT * FROM STUDENT WHERE Major = ‘CS’;

Explanation: The correct syntax retrieves all students where the major is
‘CS’.

2. Consider the ORDERS table below:


Which SQL query returns the total amount for all orders?

a) SELECT COUNT(Amount) FROM ORDERS;

b) SELECT SUM(Amount) FROM ORDERS;

c) SELECT AVG(Amount) FROM ORDERS;

d) SELECT TOTAL(Amount) FROM ORDERS;

Answer: b) SELECT SUM(Amount) FROM ORDERS;

Explanation: The SUM function aggregates the total value of the Amount
column.

3. Given the EMPLOYEE table with columns EmpID, Name, and


Department, write an SQL query to retrieve all unique departments.

a) SELECT DISTINCT Department FROM EMPLOYEE;

b) SELECT Department FROM EMPLOYEE GROUP BY Department;

c) SELECT UNIQUE Department FROM EMPLOYEE;

d) SELECT ALL Department FROM EMPLOYEE;

Answer: a) SELECT DISTINCT Department FROM EMPLOYEE;

Explanation: The DISTINCT keyword eliminates duplicate values from the


selected column.

Section 2: Relational Algebra


4. Given the relation PRODUCTS(ProductID, Name, Price, Category), what
relational algebra expression retrieves all products priced above 500?

a) π(Name) (σ Price > 500 (PRODUCTS))

b) σ Price > 500 (π Name (PRODUCTS))

c) σ Price < 500 (PRODUCTS)

d) π Price (σ Price > 500 (PRODUCTS))

Answer: a) π(Name) (σ Price > 500 (PRODUCTS))

Explanation: First, the selection operation σ Price > 500 filters rows, then
projection π(Name) selects the Name attribute.

5. Consider the relations EMPLOYEE(EmpID, Name, DeptID) and


DEPARTMENT(DeptID, DeptName). Which relational algebra operation
retrieves employees with department names?

a) EMPLOYEE ⨝ DEPARTMENT

b) π(Name, DeptName) (EMPLOYEE ⋈ DEPARTMENT)

c) σ DeptID=DeptName (EMPLOYEE ⋈ DEPARTMENT)

d) ρ(Name, DeptName) (EMPLOYEE ⋈ DEPARTMENT)

Answer: b) π(Name, DeptName) (EMPLOYEE ⋈ DEPARTMENT)

Explanation: The natural join ⋈ combines both relations based on common


attributes, and projection π selects specific columns.
Section 3: Normalization

6. Given the relation STUDENT(StudentID, Name, Address, Course,


Instructor), which of the following indicates a violation of 2NF?

a) StudentID → Name, Address, Course, Instructor

b) Course → Instructor

c) StudentID, Course → Instructor

d) Instructor → Course

Answer: b) Course → Instructor

Explanation: If Course determines Instructor, it means the relation has a


partial dependency, violating 2NF.

7. Identify the highest normal form for the relation below:

Functional dependencies:

OrderID → CustomerName, ProductName, Quantity

ProductName → Quantity

a) 1NF

b) 2NF
c) 3NF

d) BCNF

Answer: a) 1NF

Explanation: Since ProductName → Quantity creates a transitive dependency,


the relation is in 1NF but not 2NF.

Section 4: ER Diagram Interpretation

8. In the ER diagram below, the relationship WORKS_FOR between


EMPLOYEE and DEPARTMENT has a 1:N cardinality. What does this
mean?

EMPLOYEE --------< WORKS_FOR >-------- DEPARTMENT

a) One department has one employee.

b) Each department can have multiple employees.

c) Each employee can work in multiple departments.

d) Employees and departments have a many-to-many relationship.

Answer: b) Each department can have multiple employees.

Explanation: The 1:N cardinality indicates that one department can be


associated with many employees.
9. Which symbol represents a weak entity in an ER diagram?

a) Single rectangle

b) Double rectangle

c) Diamond

d) Oval

Answer: b) Double rectangle

Explanation: Weak entities are represented by double rectangles to indicate


their dependency on a strong entity.

Section 5: Transactions and Constraints

10. If a database transaction violates referential integrity, which of


the following statements is true?

a) The transaction is allowed with a warning.

b) The transaction is rolled back.

c) The transaction is ignored.

d) The transaction updates partial data.

Answer: b) The transaction is rolled back.

Explanation: A violation of referential integrity leads to transaction failure


and rollback.
11. Given the SQL statement below, what will happen if EmpID is a
primary key and the value 101 already exists?

INSERT INTO EMPLOYEE(EmpID, Name) VALUES (101, ‘Alice’);

a) The row is inserted successfully.

b) An error occurs due to duplicate primary key.

c) The existing row is updated.

d) The row is ignored silently.

Answer: b) An error occurs due to duplicate primary key.

Explanation: A primary key constraint enforces uniqueness, preventing


duplicate values.

Section 6: Design Scenarios

12. A university wants to track courses, students, and instructors.


Which is the best approach?

a) Store all data in a single table.

b) Create separate tables for courses, students, and instructors with


relationships.

c) Use a flat file system.

d) Store all data in JSON format.


Answer: b) Create separate tables for courses, students, and instructors with
relationships.

Explanation: Normalization and proper relational design help avoid


redundancy and anomalies.

Would you like more questions or detailed explanations for any specific
topics?

Here are additional practical database-related questions covering various


aspects, including SQL queries, normalization, ER modeling, and relational
algebra.

Section 7: SQL Queries

13. Given the following tables:

CUSTOMERS Table:

ORDERS Table:

Which SQL query retrieves customer names with orders greater than 250?

a)
SELECT Name FROM CUSTOMERS

WHERE CustID IN (SELECT CustID FROM ORDERS WHERE Amount > 250);

b)

SELECT Name FROM CUSTOMERS

JOIN ORDERS ON CUSTOMERS.CustID = ORDERS.CustID

WHERE Amount > 250;

c)

SELECT Name FROM CUSTOMERS

WHERE Amount > 250;

d)

SELECT DISTINCT Name FROM CUSTOMERS

WHERE Amount > 250;

Answer: b)

Explanation: A join operation is required to retrieve customer names


associated with orders greater than 250.

14. What will the following SQL query return?


SELECT COUNT(*) FROM EMPLOYEE WHERE Salary > 50000;

a) The total salary of employees earning more than 50,000

b) The number of employees earning more than 50,000

c) The sum of salaries of all employees

d) The number of employees in the EMPLOYEE table

Answer: b) The number of employees earning more than 50,000

Explanation: COUNT(*) counts the number of rows that satisfy the given
condition.

15. Which SQL statement correctly removes all rows from the
PRODUCTS table but keeps the table structure?

a) DELETE FROM PRODUCTS;

b) TRUNCATE TABLE PRODUCTS;

c) DROP TABLE PRODUCTS;

d) ALTER TABLE PRODUCTS DELETE;

Answer: b) TRUNCATE TABLE PRODUCTS;

Explanation: The TRUNCATE statement removes all records while retaining


the table structure.
Section 8: Relational Algebra

16. Given the relation EMPLOYEE(EmpID, Name, Department, Salary),


what does the following relational algebra query return?

Π Name, Department (σ Salary > 50000 (EMPLOYEE))

a) Names and departments of employees earning more than 50,000

b) All employee details

c) Employees grouped by department

d) Employee names only

Answer: a) Names and departments of employees earning more than 50,000

Explanation: The selection (σ Salary > 50000) filters rows, and projection (π
Name, Department) returns specific columns.

17. What is the result of the following relational algebra expression?

Π Name (σ City = ‘London’ (CUSTOMERS)) ⨝ ORDERS

a) All customer names from London and their orders

b) Customers from any city and their orders

c) Orders placed by all customers

d) Customers and orders with no filtering


Answer: a) All customer names from London and their orders

Explanation: The selection operation filters London customers first, followed


by the join with orders.

Section 9: Normalization

18. Which of the following scenarios indicates a violation of 3NF?

a) A non-key attribute depends on the entire primary key.

b) A non-key attribute depends on another non-key attribute.

c) The table has no composite key.

d) The primary key is a single column.

Answer: b) A non-key attribute depends on another non-key attribute.

Explanation: 3NF requires that all non-key attributes depend only on the
primary key, avoiding transitive dependencies.

19. Consider the relation STUDENT(StudentID, Name, DOB, Course,


Instructor). Which normalization form does it achieve if:

StudentID is the primary key.

Course determines Instructor.


No repeating groups exist.

a) 1NF

b) 2NF

c) 3NF

d) BCNF

Answer: a) 1NF

Explanation: Since Course → Instructor implies partial dependency, it is not


yet in 2NF.

Section 10: ER Modeling

20. In an ER diagram, if an entity STUDENT has an attribute


PhoneNumber that can have multiple values, how is it represented?

a) Using a single oval

b) Using a double oval

c) Using a rectangle

d) Using a diamond

Answer: b) Using a double oval

Explanation: Multivalued attributes are shown with a double oval in ER


diagrams.
21. Which of the following is an example of a ternary relationship?

a) A student enrolls in a course taught by a professor.

b) A customer orders a product.

c) An employee belongs to a department.

d) A supplier provides products to customers.

Answer: a) A student enrolls in a course taught by a professor.

Explanation: This relationship involves three entities: student, course, and


professor.

Section 11: Transactions

22. Which ACID property ensures that changes made by a committed


transaction are permanently stored?

a) Atomicity

b) Consistency

c) Isolation

d) Durability

Answer: d) Durability

Explanation: Durability ensures that committed changes persist even in the


event of system failures.
23. What happens when a deadlock occurs in a DBMS?

a) Transactions continue execution.

b) The database terminates.

c) Transactions wait indefinitely.

d) The DBMS rolls back one of the transactions.

Answer: d) The DBMS rolls back one of the transactions.

Explanation: To resolve deadlocks, the DBMS may roll back one of the
conflicting transactions.

Section 12: Database Design

24. Which strategy is best for handling many-to-many relationships


in a relational database?

a) Create an associative table with foreign keys to both entities.

b) Merge both entities into a single table.

c) Use a foreign key in one table pointing to another.

d) Store related data in separate text files.

Answer: a) Create an associative table with foreign keys to both entities.


Explanation: Many-to-many relationships require an associative table to store
links between the related entities.

25. In a hospital database, a patient can be assigned to multiple


doctors, and doctors can have multiple patients. Which ERD
representation is correct?

a) One-to-Many (1:N)

b) Many-to-Many (M:N)

c) One-to-One (1:1)

d) Unary Relationship

Answer: b) Many-to-Many (M:N)

Explanation: Patients can have multiple doctors, and doctors can have
multiple patients, requiring an M:N relationship.

Would you like more practice questions or specific topics explained in detail?

Here are more practical database questions focusing on SQL queries, ERD
diagrams, relational algebra, and critical thinking scenarios.
Section 13: SQL Queries

26. Given the following EMPLOYEE table:

Which query will return the second highest salary from the table?

a)

SELECT MAX(Salary) FROM EMPLOYEE;

b)

SELECT DISTINCT Salary FROM EMPLOYEE ORDER BY Salary DESC LIMIT 1,1;

c)

SELECT MAX(Salary) FROM EMPLOYEE WHERE Salary < (SELECT MAX(Salary)


FROM EMPLOYEE);

d)

SELECT TOP 2 Salary FROM EMPLOYEE ORDER BY Salary DESC;

Answer: c)

Explanation: This query first finds the maximum salary, then retrieves the
next highest value.
27. Consider the ORDERS and CUSTOMERS tables:

ORDERS Table:

CUSTOMERS Table:

Which SQL query retrieves all customers who have not placed an order?

a)

SELECT Name FROM CUSTOMERS

WHERE CustID NOT IN (SELECT CustID FROM ORDERS);

b)

SELECT Name FROM CUSTOMERS

LEFT JOIN ORDERS ON CUSTOMERS.CustID = ORDERS.CustID

WHERE ORDERS.CustID IS NULL;

c)

SELECT Name FROM CUSTOMERS

WHERE CustID = NULL;

d)
SELECT Name FROM CUSTOMERS

WHERE CustID != ALL (SELECT CustID FROM ORDERS);

Answer: b)

Explanation: A LEFT JOIN with a WHERE clause filtering NULL values correctly
finds non-matching records.

28. Given the PRODUCTS table, how would you retrieve the top 3
highest-priced products?

| ProductID | ProductName | Price |

|1 | Laptop | 1500 |

|2 | Phone | 1000 |

|3 | TV | 1200 |

|4 | Tablet | 800 |

a)

SELECT * FROM PRODUCTS ORDER BY Price DESC LIMIT 3;

b)

SELECT * FROM PRODUCTS ORDER BY Price DESC FETCH FIRST 3 ROWS


ONLY;
c)

SELECT * FROM PRODUCTS ORDER BY Price ASC LIMIT 3;

d)

SELECT TOP 3 * FROM PRODUCTS ORDER BY Price DESC;

Answer: a)

Explanation: LIMIT 3 retrieves the top 3 products when sorted in descending


order by price.

Section 14: ER Diagrams and Critical Thinking

29. Analyze the following ERD and determine what normalization


issue exists.

STUDENT (StudentID, Name, Address, CourseID, CourseName, Instructor)

Question: What normalization issue exists in the given design?

a) Partial Dependency

b) Transitive Dependency

c) Repeating Groups

d) No Issue
Answer: b) Transitive Dependency

Explanation: CourseName and Instructor depend on CourseID, not directly on


StudentID, violating 3NF.

30. Consider the relationship between PATIENT, DOCTOR, and


HOSPITAL. If a patient can visit multiple doctors in different hospitals,
what type of relationship is this?

a) One-to-One (1:1)

b) One-to-Many (1:M)

c) Many-to-Many (M:N)

d) Recursive Relationship

Answer: c) Many-to-Many (M:N)

Explanation: A patient can visit multiple doctors, and doctors can attend to
multiple patients, requiring an associative table.

31. Which of the following best represents the primary key in the
relationship below?

EMPLOYEE (EmpID, Name, Department)

DEPARTMENT (DeptID, DeptName)

WORKS_ON (EmpID, DeptID, Hours)


a) EmpID

b) DeptID

c) (EmpID, DeptID)

d) Hours

Answer: c) (EmpID, DeptID)

Explanation: The combination of EmpID and DeptID uniquely identifies each


work assignment.

Section 15: Query Optimization and Execution

32. Given the query below, what index would optimize its
performance?

SELECT * FROM EMPLOYEE WHERE Department = ‘IT’;

a) Clustered index on Department

b) Non-clustered index on Department

c) Full table scan

d) Composite index on Department, Salary

Answer: b) Non-clustered index on Department

Explanation: A non-clustered index improves performance for queries


filtering by non-primary key columns.
33. If a table has frequent updates, which indexing strategy should
be avoided?

a) B-Tree Index

b) Hash Index

c) Clustered Index

d) Bitmap Index

Answer: d) Bitmap Index

Explanation: Bitmap indexes are not efficient for frequently updated tables
due to their static nature.

Section 16: Transactions and Deadlocks

34. What SQL command is used to start a transaction explicitly?

a) BEGIN;

b) START TRANSACTION;

c) OPEN TRANSACTION;

d) TRANSACTION START;

Answer: b) START TRANSACTION;

Explanation: This command explicitly begins a transaction in SQL.


35. In case of a deadlock in a DBMS, what is the best resolution
strategy?

a) Kill the database instance

b) Allow transactions to retry indefinitely

c) Rollback the youngest transaction

d) Rollback the least expensive transaction

Answer: c) Rollback the youngest transaction

Explanation: DBMS systems typically select the youngest transaction for


rollback to resolve deadlocks efficiently.

Section 17: Database Design Decisions

36. In which scenario would you recommend denormalization?

a) When query performance is slow due to excessive joins

b) When minimizing data redundancy is the top priority

c) When storage space is a primary concern

d) When relationships between entities are complex

Answer: a) When query performance is slow due to excessive joins


Explanation: Denormalization improves query performance by reducing joins
at the cost of some redundancy.

37. Which of the following best explains why surrogate keys are used
instead of natural keys?

a) Surrogate keys improve data redundancy

b) Surrogate keys provide better performance and are unique

c) Natural keys are easier to remember

d) Surrogate keys are always sequential integers

Answer: b) Surrogate keys provide better performance and are unique

Explanation: Surrogate keys are system-generated and ensure uniqueness


without dependencies on existing attributes.

Would you like more case studies or queries for practice?

Database Systems – Sample Final Exam (New Version)

Module Title: Database Systems

Module Code: 20CSIC03C

Semester: One

Time Allowed: 2 Hours


Total Marks: 100

Instructions to Students:

Answer ALL questions.

Marks allocation is shown in brackets.

No equipment allowed.

Question 1: Conceptual Understanding [25 Marks]

a) Explain the following database concepts: [2 marks each]

i. Data Dictionary

ii. Foreign Key

iii. Specialization in EERD

iv. DML

b) Discuss the importance of the ACID properties in database transactions


and explain how they ensure data integrity. [7 marks]

c) Determine whether the following statements are TRUE or FALSE with


justification. [10 marks]

i. A foreign key in a relational database must always be a


primary key in the referenced table.
ii. Functional dependencies are used to determine the
normalization of a relation.
iii. SQL is a procedural language.

iv. In relational algebra, the Cartesian product produces a new relation by


combining tuples.

iv. BCNF ensures that there are no transitive dependencies in the


relation.

Question 2: SQL Queries and Relational Algebra [25 Marks]

Consider the following schema:

PRODUCT (PID, PName, Price, CategoryID)

CATEGORY (CategoryID, CategoryName)

a) Write a relational algebra expression to retrieve product names


and category names for products priced above 1000. [7 marks]

b) Write an SQL query to retrieve each category name along with


the total number of products in that category. [6 marks]

c) Given relations A(X, Y) with 300 tuples and B(Y, Z) with 400
tuples, estimate the number of tuples for the following relational
operations and justify your answer: [12 marks]

A⋈B
i. Π X(A)
ii.
iii. A ∪ B (assuming compatibility)
iv. Σ Y > 500 (A)

Question 3: ERD and Relationship Constraints [30 Marks]

Given the ER Diagram below, answer the following questions:

Database Systems – Sample Final Exam (New Version)

Module Title: Database Systems

Module Code: 20CSIC03C

Semester: One

Time Allowed: 2 Hours

Total Marks: 100

Instructions to Students:

Answer ALL questions.

Marks allocation is shown in brackets.

No equipment allowed.

Question 1: Conceptual Understanding [25 Marks]


a) Explain the following database concepts: [2 marks each]

i. Data Dictionary

ii. Foreign Key

iii. Specialization in EERD

v. DML

b) Discuss the importance of the ACID properties in database transactions


and explain how they ensure data integrity. [7 marks]

d) Determine whether the following statements are TRUE or FALSE


with justification. [10 marks]

i. A foreign key in a relational database must always be


a primary key in the referenced table.
ii. Functional dependencies are used to determine the
normalization of a relation.
iii. SQL is a procedural language.

iv. In relational algebra, the Cartesian product produces a new relation by


combining tuples.

iv. BCNF ensures that there are no transitive


dependencies in the relation.

Question 2: SQL Queries and Relational Algebra [25 Marks]

Consider the following schema:


PRODUCT (PID, PName, Price, CategoryID)

CATEGORY (CategoryID, CategoryName)

a) Write a relational algebra expression to retrieve product names


and category names for products priced above 1000. [7 marks]

b) Write an SQL query to retrieve each category name along with


the total number of products in that category. [6 marks]

c) Given relations A(X, Y) with 300 tuples and B(Y, Z) with 400
tuples, estimate the number of tuples for the following relational
operations and justify your answer: [12 marks]

A⋈B
i. Π X(A)

A ∪ B (assuming compatibility)
ii.
iii.
iv. Σ Y > 500 (A)

Question 3: ERD and Relationship Constraints [30 Marks]

Given the ER Diagram below, answer the following questions:

Entities: CUSTOMER (CustID, Name), ORDER (OrderID, Date), ITEM (ItemID,


Description)

Relationships:
CUSTOMER places multiple ORDERS (1:M)

ORDER contains multiple ITEMS (M:N)

a) Briefly explain the meaning of the ER diagram. [6 marks]

b) Represent the relationship constraints using (min, max) notation.


[8 marks]

c) If there are 50 customers, 200 orders, and 500 items, what is the
maximum number of records in the relationship table between
ORDER and ITEM? [6 marks]

d) Convert the ER diagram into relational schema including primary


and foreign keys. [10 marks]

Question 4: Normalization and Anomalies [20 Marks]

Consider the following relation storing employee project assignments:

Functional Dependencies:

EmpID → EmpName

ProjectID → ProjectName
(EmpID, ProjectID) → HoursWorked

a) Identify the highest normal form the relation satisfies and explain
why. [5 marks]

b) Give an example of an update and a delete anomaly that may


occur in the current relation. [7 marks]

c) Normalize the relation to 3NF and provide the decomposed


relations. [8 marks]

Model Answers and Explanations

Question 1: Conceptual Understanding

a)

i. Data Dictionary: A centralized repository of metadata that provides details


about database schema, structure, and constraints.

ii. Foreign Key: A field in one table that uniquely identifies a row in another
table, establishing referential integrity.

iii. Specialization in EERD: A process of defining a set of sub-entities that


inherit common attributes from a general entity.

v. DML (Data Manipulation Language): SQL commands


used to retrieve and manipulate data, such as SELECT,
INSERT, UPDATE, and DELETE.

b)
ACID properties ensure:

Atomicity: Transactions are all-or-nothing.

Consistency: Ensures data remains valid before and after the transaction.

Isolation: Transactions execute independently.

Durability: Once committed, data changes persist permanently.

c)

i. FALSE – A foreign key can reference any unique column.

ii. TRUE – Functional dependencies are crucial for normalization.

iii. FALSE – SQL is a declarative language.

iv. TRUE – Cartesian product results in all possible combinations.

vi. FALSE – BCNF focuses on eliminating functional


dependencies, not transitive dependencies.

Question 2: SQL Queries and Relational Algebra

a)

Relational Algebra:

Π PName, CategoryName (σ Price > 1000 (PRODUCT ⋈ CATEGORY))


b)

SQL Query:

SELECT C.CategoryName, COUNT(P.PID) AS TotalProducts

FROM CATEGORY C

LEFT JOIN PRODUCT P ON C.CategoryID = P.CategoryID

GROUP BY C.CategoryName;

c)

i. π X(A) = 300 tuples (assuming no duplicates).

ii. A ⋈ B = 300 * 400 = 120,000 tuples (cartesian product).

iii. A ∪ B = 300 + 400 = 700 tuples (if no overlap).

v. σ Y > 500 (A) = A subset of 300 tuples (depends on


data distribution).

---

Question 3: ERD and Relationship Constraints

a)

The diagram shows that customers place orders, and each order contains
multiple items.

b)

Min-max notation:
CUSTOMER places ORDER (1, N)

ORDER contains ITEM (1, N)

c)

Maximum relationship entries: 200 orders × 500 items = 100,000 entries.

d)

Relational Schema:

CUSTOMER (CustID PRIMARY KEY, Name)

ORDER (OrderID PRIMARY KEY, CustID FOREIGN KEY REFERENCES


CUSTOMER)

ITEM (ItemID PRIMARY KEY, Description)

ORDER_ITEM (OrderID FOREIGN KEY REFERENCES ORDER, ItemID FOREIGN


KEY REFERENCES ITEM)

---

Question 4: Normalization and Anomalies

a)

The relation violates 2NF due to partial dependencies (EmpID → EmpName,


ProjectID → ProjectName).
b)

Update Anomaly: Updating the project name requires multiple updates.

Delete Anomaly: Deleting an employee removes project details.

c)

Normalized to 3NF:

EMPLOYEE (EmpID, EmpName)

PROJECT (ProjectID, ProjectName)

ASSIGNMENT (EmpID, ProjectID, HoursWorked)

---

Would you like additional practice exams or specific topics covered in more
detail?

Entities: CUSTOMER (CustID, Name), ORDER (OrderID, Date), ITEM (ItemID,


Description)

Relationships:
CUSTOMER places multiple ORDERS (1:M)

ORDER contains multiple ITEMS (M:N)

d) Briefly explain the meaning of the ER diagram. [6 marks]

e) Represent the relationship constraints using (min, max) notation.


[8 marks]

f) If there are 50 customers, 200 orders, and 500 items, what is the
maximum number of records in the relationship table between
ORDER and ITEM? [6 marks]

g) Convert the ER diagram into relational schema including primary


and foreign keys. [10 marks]

Question 4: Normalization and Anomalies [20 Marks]

Consider the following relation storing employee project assignments:

Functional Dependencies:

EmpID → EmpName

ProjectID → ProjectName
(EmpID, ProjectID) → HoursWorked

e) Identify the highest normal form the relation satisfies and explain
why. [5 marks]

f) Give an example of an update and a delete anomaly that may


occur in the current relation. [7 marks]

g) Normalize the relation to 3NF and provide the decomposed


relations. [8 marks]

Model Answers and Explanations

Question 1: Conceptual Understanding

a)

i. Data Dictionary: A centralized repository of metadata that provides details


about database schema, structure, and constraints.

ii. Foreign Key: A field in one table that uniquely identifies a row in another
table, establishing referential integrity.

iii. Specialization in EERD: A process of defining a set of sub-entities that


inherit common attributes from a general entity.

vi. DML (Data Manipulation Language): SQL commands


used to retrieve and manipulate data, such as SELECT,
INSERT, UPDATE, and DELETE.

b)
ACID properties ensure:

Atomicity: Transactions are all-or-nothing.

Consistency: Ensures data remains valid before and after the transaction.

Isolation: Transactions execute independently.

Durability: Once committed, data changes persist permanently.

c)

i. FALSE – A foreign key can reference any unique column.

ii. TRUE – Functional dependencies are crucial for normalization.

iii. FALSE – SQL is a declarative language.

iv. TRUE – Cartesian product results in all possible combinations.

vii. FALSE – BCNF focuses on eliminating functional


dependencies, not transitive dependencies.

Question 2: SQL Queries and Relational Algebra

a)

Relational Algebra:

Π PName, CategoryName (σ Price > 1000 (PRODUCT ⋈ CATEGORY))


b)

SQL Query:

SELECT C.CategoryName, COUNT(P.PID) AS TotalProducts

FROM CATEGORY C

LEFT JOIN PRODUCT P ON C.CategoryID = P.CategoryID

GROUP BY C.CategoryName;

c)

i. π X(A) = 300 tuples (assuming no duplicates).

ii. A ⋈ B = 300 * 400 = 120,000 tuples (cartesian product).

iii. A ∪ B = 300 + 400 = 700 tuples (if no overlap).

v. Σ Y > 500 (A) = A subset of 300 tuples (depends on data


distribution).

Question 3: ERD and Relationship Constraints

a)

The diagram shows that customers place orders, and each order contains
multiple items.

b)

Min-max notation:
CUSTOMER places ORDER (1, N)

ORDER contains ITEM (1, N)

c)

Maximum relationship entries: 200 orders × 500 items = 100,000 entries.

d)

Relational Schema:

CUSTOMER (CustID PRIMARY KEY, Name)

ORDER (OrderID PRIMARY KEY, CustID FOREIGN KEY REFERENCES


CUSTOMER)

ITEM (ItemID PRIMARY KEY, Description)

ORDER_ITEM (OrderID FOREIGN KEY REFERENCES ORDER, ItemID FOREIGN


KEY REFERENCES ITEM)

Question 4: Normalization and Anomalies

a)

The relation violates 2NF due to partial dependencies (EmpID → EmpName,


ProjectID → ProjectName).

b)
Update Anomaly: Updating the project name requires multiple updates.

Delete Anomaly: Deleting an employee removes project details.

c)

Normalized to 3NF:

EMPLOYEE (EmpID, EmpName)

PROJECT (ProjectID, ProjectName)

ASSIGNMENT (EmpID, ProjectID, HoursWorked)

Would you like additional practice exams or specific topics covered in more
detail?

Database Systems - Sample Final Exam (New Version)

Module Title: Database Systems


Module Code: 20CSIC03C
Semester: One
Time Allowed: 2 Hours
Total Marks: 100
Instructions to Students:

 Answer ALL questions.


 Marks allocation is shown in brackets.
 No equipment allowed.
Question 1: Conceptual Understanding [25 Marks]

a) Explain the following database concepts: [2 marks each]


i. Data Dictionary
ii. Foreign Key
iii. Specialization in EERD
iv. DML

b) Discuss the importance of the ACID properties in database transactions and explain how they
ensure data integrity. [7 marks]

c) Determine whether the following statements are TRUE or FALSE with justification. [10
marks]

i. A foreign key in a relational database must always be a primary key in the referenced table.
ii. Functional dependencies are used to determine the normalization of a relation.
iii. SQL is a procedural language.
iv. In relational algebra, the Cartesian product produces a new relation by combining tuples.
v. BCNF ensures that there are no transitive dependencies in the relation.

Question 2: SQL Queries and Relational Algebra [25 Marks]

Consider the following schema:

PRODUCT (PID, PName, Price, CategoryID)


CATEGORY (CategoryID, CategoryName)

a) Write a relational algebra expression to retrieve product names and category names for
products priced above 1000. [7 marks]

b) Write an SQL query to retrieve each category name along with the total number of products in
that category. [6 marks]

c) Given relations A(X, Y) with 300 tuples and B(Y, Z) with 400 tuples, estimate the number of
tuples for the following relational operations and justify your answer: [12 marks]

ii. A ⋈ B
i. π X(A)

iii. A ∪ B (assuming compatibility)


iv. σ Y > 500 (A)
Question 3: ERD and Relationship Constraints [30 Marks]

Given the ER Diagram below, answer the following questions:

 Entities: CUSTOMER (CustID, Name), ORDER (OrderID, Date), ITEM


(ItemID, Description)
 Relationships:
o CUSTOMER places multiple ORDERS (1:M)
o ORDER contains multiple ITEMS (M:N)

a) Briefly explain the meaning of the ER diagram. [6 marks]

b) Represent the relationship constraints using (min, max) notation. [8 marks]

c) If there are 50 customers, 200 orders, and 500 items, what is the maximum number of records
in the relationship table between ORDER and ITEM? [6 marks]

d) Convert the ER diagram into relational schema including primary and foreign keys. [10
marks]

Question 4: Normalization and Anomalies [20 Marks]

Consider the following relation storing employee project assignments:

Functional Dependencies:
EmpID → EmpName
ProjectID → ProjectName
(EmpID, ProjectID) → HoursWorked

a) Identify the highest normal form the relation satisfies and explain why. [5 marks]

b) Give an example of an update and a delete anomaly that may occur in the current relation. [7
marks]

c) Normalize the relation to 3NF and provide the decomposed relations. [8 marks]

Model Answers and Explanations


Question 1: Conceptual Understanding

a)
i. Data Dictionary: A centralized repository of metadata that provides details about database
schema, structure, and constraints.
ii. Foreign Key: A field in one table that uniquely identifies a row in another table, establishing
referential integrity.
iii. Specialization in EERD: A process of defining a set of sub-entities that inherit common
attributes from a general entity.
iv. DML (Data Manipulation Language): SQL commands used to retrieve and manipulate
data, such as SELECT, INSERT, UPDATE, and DELETE.

b)
ACID properties ensure:

 Atomicity: Transactions are all-or-nothing.


 Consistency: Ensures data remains valid before and after the
transaction.
 Isolation: Transactions execute independently.
 Durability: Once committed, data changes persist permanently.

c)
i. FALSE – A foreign key can reference any unique column.
ii. TRUE – Functional dependencies are crucial for normalization.
iii. FALSE – SQL is a declarative language.
iv. TRUE – Cartesian product results in all possible combinations.
v. FALSE – BCNF focuses on eliminating functional dependencies, not transitive dependencies.

Question 2: SQL Queries and Relational Algebra

a)
Relational Algebra:

π PName, CategoryName (σ Price > 1000 (PRODUCT ⋈ CATEGORY))

b)
SQL Query:

SELECT C.CategoryName, COUNT(P.PID) AS TotalProducts


FROM CATEGORY C
LEFT JOIN PRODUCT P ON C.CategoryID = P.CategoryID
GROUP BY C.CategoryName;

c)

ii. A ⋈ B = 300 * 400 = 120,000 tuples (cartesian product).


i. π X(A) = 300 tuples (assuming no duplicates).

iii. A ∪ B = 300 + 400 = 700 tuples (if no overlap).


iv. σ Y > 500 (A) = A subset of 300 tuples (depends on data distribution).
Question 3: ERD and Relationship Constraints

a)
The diagram shows that customers place orders, and each order contains multiple items.

b)
Min-max notation:

 CUSTOMER places ORDER (1, N)


 ORDER contains ITEM (1, N)

c)
Maximum relationship entries: 200 orders × 500 items = 100,000 entries.

d)
Relational Schema:

CUSTOMER (CustID PRIMARY KEY, Name)


ORDER (OrderID PRIMARY KEY, CustID FOREIGN KEY REFERENCES CUSTOMER)
ITEM (ItemID PRIMARY KEY, Description)
ORDER_ITEM (OrderID FOREIGN KEY REFERENCES ORDER, ItemID FOREIGN KEY
REFERENCES ITEM)

Question 4: Normalization and Anomalies

a)
The relation violates 2NF due to partial dependencies (EmpID → EmpName, ProjectID →
ProjectName).

b)

 Update Anomaly: Updating the project name requires multiple


updates.
 Delete Anomaly: Deleting an employee removes project details.

c)
Normalized to 3NF:

EMPLOYEE (EmpID, EmpName)


PROJECT (ProjectID, ProjectName)
ASSIGNMENT (EmpID, ProjectID, HoursWorked)

Would you like additional practice exams or specific topics covered in more detail?
Database Systems - Practice Final Exam (Version 2)

Module Title: Database Systems


Module Code: 20CSIC03C
Semester: One
Time Allowed: 2 Hours
Total Marks: 100
Instructions to Students:

 Answer ALL questions.


 Marks allocation is shown in brackets.
 No equipment allowed.

Question 1: Conceptual Understanding [25 Marks]

a) Define and explain the following database concepts: [2 marks each]


i. Primary Key
ii. Referential Integrity
iii. Generalization in EERD
iv. DCL (Data Control Language)

b) Explain the role of a database management system (DBMS) in ensuring data integrity and
security. [7 marks]

c) Determine whether the following statements are TRUE or FALSE with justification. [10
marks]

i. In an ER diagram, attributes of relationships cannot have their own attributes.


ii. A candidate key is always chosen as the primary key.
iii. SQL views help in enforcing security by restricting access to specific columns or rows.
iv. The Cartesian product in relational algebra always results in duplicate tuples.
v. A relation in 2NF eliminates all transitive dependencies.

Question 2: SQL Queries and Relational Algebra [25 Marks]

Consider the following schema:

EMPLOYEE (EmpID, EmpName, Salary, DeptID)


DEPARTMENT (DeptID, DeptName)

a) Write a relational algebra expression to retrieve the employee names and department names
for employees earning more than 5000. [7 marks]
b) Write an SQL query to find the total salary paid to employees in each department. [6 marks]

c) Consider relations R(A, B) with 150 tuples and S(B, C) with 200 tuples. Estimate the number
of tuples for the following operations and justify your answer: [12 marks]

ii. R ⋈ S
i. π A(R)

iii. R ∩ S (assuming compatibility)


iv. σ B < 100 (S)

Question 3: ERD and Relationship Constraints [30 Marks]

Scenario: A university maintains a database to track professors, courses, and students.


Professors teach multiple courses, and students can enroll in multiple courses.

Entities and Attributes:

 PROFESSOR (ProfID, Name, Department)


 COURSE (CourseID, Title, Credits)
 STUDENT (StudentID, Name, Major)

Relationships:

 A professor can teach multiple courses.


 A student can enroll in multiple courses.

ER Diagram:

An ER diagram illustrating the relationship between PROFESSOR, COURSE, and STUDENT


entities for a university database system.

Entities and Attributes:

 PROFESSOR (ProfID - Primary Key, Name, Department)


 COURSE (CourseID - Primary Key, Title, Credits)
 STUDENT (StudentID - Primary Key, Name, Major)

Relationships:

1. A PROFESSOR can teach multiple COURSES (1:M relationship).


2. A STUDENT can enroll in multiple COURSES, and a COURSE can have
multiple STUDENTS (M:N relationship).
Diagram Structure:

 Rectangles for entities (PROFESSOR, COURSE, STUDENT).


 Diamonds for relationships (TEACHES, ENROLLS).
 Connecting lines indicating relationships:
o PROFESSOR (1,1) to COURSE (0,N) via TEACHES.
o STUDENT (1,N) to COURSE (1,N) via ENROLLS.

a) Explain the meaning of the ER diagram based on the given scenario. [6 marks]

b) Represent the relationship constraints using (min, max) notation. [8 marks]

c) If there are 30 professors, 100 courses, and 500 students, what is the maximum number of
enrollments in the relationship? [6 marks]

d) Convert the ER diagram to relational schema with primary and foreign keys. [10 marks]

Question 4: Normalization and Anomalies [20 Marks]

Consider the following relation storing purchase transactions:

Functional Dependencies:
TransactionID → PurchaseDate
ProductID → ProductName
CustomerID → CustomerName
(TransactionID, ProductID) → PurchaseDate

a) Identify the highest normal form the relation satisfies and explain why. [5 marks]

b) Provide an example of an insertion anomaly and a deletion anomaly. [7 marks]

c) Normalize the relation to 3NF and provide the decomposed relations. [8 marks]

Let me know if you need any additional information or modifications.

Database Systems – Practice Final Exam (Version 2) Model Answers


Question 1: Conceptual Understanding [25 Marks]

a) Definitions:

i. Primary Key: A unique identifier for each record in a


table that ensures uniqueness and allows efficient data
retrieval. Example: StudentID in a STUDENT table.

ii. Referential Integrity: Ensures that a foreign key value in


one table corresponds to an existing primary key value
in another table. It prevents orphan records and
maintains data consistency.

iii. Generalization in EERD: A process of combining multiple


specific entity types into a higher-level, more general
entity type based on common characteristics.

iv. DCL (Data Control Language): A subset of SQL


commands used to manage permissions and access
controls in a database, such as GRANT and REVOKE.

b) Role of a DBMS in Ensuring Data Integrity and Security:


Data Integrity:

1. Enforces constraints (Primary Key, Foreign Key, Unique, Not Null).

2. Ensures consistency through ACID transactions.

3. Prevents duplicate records using unique constraints.

Data Security:

1. Role-based access control (RBAC).

2. Data encryption.

3. Audit trails and logging.

4. Authentication mechanisms (passwords, multi-factor


authentication).
c) True/False with Justifications:

1. FALSE – Relationship attributes can have their own attributes, e.g., an


ENROLLMENT relationship can have an attribute EnrollmentDate.

2. FALSE – A candidate key is a potential primary key, but the database


designer chooses the most appropriate one.

3. TRUE – Views restrict access by limiting exposure to certain columns or


rows based on user roles.

4. FALSE – Cartesian product results in all possible combinations of tuples,


but does not inherently produce duplicates.

5. FALSE – 2NF removes partial dependencies, while transitive


dependencies are eliminated in 3NF.
Question 2: SQL Queries and Relational Algebra [25 Marks]

a) Relational Algebra Expression:

Π EmpName, DeptName (σ Salary > 5000 (EMPLOYEE ⋈ DEPARTMENT))

b) SQL Query to Find Total Salary by Department:

SELECT D.DeptName, SUM(E.Salary) AS TotalSalary

FROM EMPLOYEE E

JOIN DEPARTMENT D ON E.DeptID = D.DeptID

GROUP BY D.DeptName;

c) Tuple Estimation and Justification:

1. Π A® → Maximum of 150 tuples assuming no duplicates.

2. R ⋈ S → 150 * 200 = 30,000 tuples, assuming a Cartesian product. If


there’s an equijoin on B, the result would be fewer.
3. R ∩ S → If sets are disjoint, the result would be 0 tuples; otherwise, it
would be the minimum of both sets, which is up to 150 tuples.

4. Σ B < 100 (S) → A subset of the 200 tuples based on condition,


potentially half if values are uniformly distributed.

Question 3: ERD and Relationship Constraints [30 Marks]

a) Meaning of the ER Diagram:

The diagram represents a university system where:

1. A PROFESSOR teaches multiple COURSES (1:M).

2. A STUDENT enrolls in multiple COURSES, and a course can have many


students (M:N).

b) Relationship Constraints (Min-Max Notation):


1. PROFESSOR teaches COURSE (1, N) → A professor must teach at least
1 course but can teach many.

2. STUDENT enrolls in COURSE (0, N) → A student may enroll in many


courses or none.

c) Maximum Number of Enrollments:

Calculation:

\text{Maximum enrollments} = 30 \text{ professors } \times 100 \


text{ courses } \times 500 \text{ students } = 1,500,000 \text{ records}

d) Relational Schema Conversion:

CREATE TABLE PROFESSOR (

ProfID INT PRIMARY KEY,

Name VARCHAR(50),

Department VARCHAR(50)

);
CREATE TABLE COURSE (

CourseID INT PRIMARY KEY,

Title VARCHAR(100),

Credits INT

);

CREATE TABLE STUDENT (

StudentID INT PRIMARY KEY,

Name VARCHAR(50),

Major VARCHAR(50)

);

CREATE TABLE TEACHES (

ProfID INT,

CourseID INT,

PRIMARY KEY (ProfID, CourseID),

FOREIGN KEY (ProfID) REFERENCES PROFESSOR(ProfID),

FOREIGN KEY (CourseID) REFERENCES COURSE(CourseID)

);

CREATE TABLE ENROLLS (

StudentID INT,

CourseID INT,

PRIMARY KEY (StudentID, CourseID),

FOREIGN KEY (StudentID) REFERENCES STUDENT(StudentID),

FOREIGN KEY (CourseID) REFERENCES COURSE(CourseID)


);

Question 4: Normalization and Anomalies [20 Marks]

a) Highest Normal Form:

The given relation is in 1NF but violates 2NF due to partial dependencies
(ProductID → ProductName, CustomerID → CustomerName).

b) Insertion and Deletion Anomalies:

Insertion Anomaly: If a new product is introduced without a customer


purchasing it, redundant data is required.

Deletion Anomaly: Deleting a transaction might remove important customer


details if stored redundantly.

c) 3NF Decomposition:

Step 1: Identify dependencies and remove redundancy.

Decomposed relations:
CUSTOMER (CustomerID, CustomerName)

PRODUCT (ProductID, ProductName)

TRANSACTION (TransactionID, CustomerID, PurchaseDate)

PURCHASE_DETAILS (TransactionID, ProductID)

SQL Schema:

CREATE TABLE CUSTOMER (

CustomerID VARCHAR(10) PRIMARY KEY,

CustomerName VARCHAR(50)

);

CREATE TABLE PRODUCT (

ProductID VARCHAR(10) PRIMARY KEY,

ProductName VARCHAR(50)

);

CREATE TABLE TRANSACTION (

TransactionID VARCHAR(10) PRIMARY KEY,

CustomerID VARCHAR(10),

PurchaseDate DATE,

FOREIGN KEY (CustomerID) REFERENCES CUSTOMER(CustomerID)

);

CREATE TABLE PURCHASE_DETAILS (

TransactionID VARCHAR(10),
ProductID VARCHAR(10),

PRIMARY KEY (TransactionID, ProductID),

FOREIGN KEY (TransactionID) REFERENCES TRANSACTION(TransactionID),

FOREIGN KEY (ProductID) REFERENCES PRODUCT(ProductID)

);

Would you like further clarification on any topic or additional exercises?

Database Systems – Practice Final Exam (Version 3)

Module Title: Database Systems

Module Code: 20CSIC03C

Semester: One

Time Allowed: 2 Hours

Total Marks: 100

Instructions to Students:

Answer ALL questions.

Marks allocation is shown in brackets.

No equipment allowed.
Question 1: Conceptual Understanding [25 Marks]

a) Define and explain the following database concepts: [2 marks each]

i. Composite Key

ii. Functional Dependency

iii. Aggregation in ERD

iv. TCL (Transaction Control Language)

b) Describe the difference between logical and physical data independence


in databases. [7 marks]

d) Determine whether the following statements are TRUE or FALSE


with justification. [10 marks]

i. A relation can have more than one primary key.


ii. A derived attribute is calculated from other attributes.
iii. The SELECT operation in relational algebra filters rows
based on conditions.

iv. The UNION operation in relational algebra allows duplicate rows.

iv. In a distributed database, all data is stored in a single


location.

Question 2: SQL Queries and Relational Algebra [25 Marks]

Consider the following schema:


BOOK (BookID, Title, Price, PubID)

PUBLISHER (PubID, PubName, Location)

a) Write a relational algebra expression to retrieve the book titles


and publisher names where book prices are greater than 500. [7
marks]

b) Write an SQL query to retrieve each publisher’s name along with


the total number of books they publish. [6 marks]

c) Given relations X(A, B) with 100 tuples and Y(B, C) with 200
tuples, estimate the number of tuples for the following
operations and justify your answer: [12 marks]

X⋈Y
i. Π A(X)
ii.
iii. X ∩ Y (assuming compatibility)
iv. Σ B > 50 (Y)

Question 3: ERD and Relationship Constraints [30 Marks]

Scenario: A retail store wants to track employees, products, and sales


transactions. Employees can handle multiple transactions, and each
transaction can include multiple products.

Entities and Attributes:


EMPLOYEE (EmpID, Name, Position)

TRANSACTION (TransID, Date, EmpID)

PRODUCT (ProdID, Name, Price)

Relationships:

An EMPLOYEE can process multiple TRANSACTIONS (1:M).

A TRANSACTION can include multiple PRODUCTS (M:N).

ER Diagram (Text Representation):

| EMPLOYEE | | TRANSACTION | | PRODUCT |

| EmpID (PK) | 1 -- | TransID (PK) | -- M | ProdID (PK) |

| Name | | Date | | Name |

| Position | | EmpID (FK) | | Price |

TRANSACTION_DETAILS (TransID, ProdID, Quantity)


a) Explain the meaning of the ER diagram based on the given
scenario. [6 marks]

b) Represent the relationship constraints using (min, max)


notation. [8 marks]

c) If there are 50 employees, 200 transactions, and 500


products, what is the maximum number of records in the
relationship table TRANSACTION_DETAILS? [6 marks]

d) Convert the ER diagram to relational schema including


primary and foreign keys. [10 marks]

Question 4: Normalization and Anomalies [20 Marks]

Consider the following relation storing order details:

Functional Dependencies:

OrderID → CustomerID, ProductID, Quantity

CustomerID → CustomerName

ProductID → ProductName
a) Identify the highest normal form the relation satisfies and
explain why. [5 marks]

b) Provide an example of an insertion anomaly and a deletion


anomaly. [7 marks]

c) Normalize the relation to 3NF and provide the decomposed


relations. [8 marks]

Model Answers

Question 1: Conceptual Understanding

a) Definitions:

i. Composite Key: A key consisting of two or more attributes that uniquely


identify a record in a table.

ii. Functional Dependency: A relationship where a set of attributes uniquely


determines another attribute.

iii. Aggregation in ERD: A higher-level abstraction where a relationship itself


is treated as an entity.

v. TCL: Transaction Control Language commands like


COMMIT, ROLLBACK, and SAVEPOINT used to manage
transactions.
b)

Logical Data Independence: Ability to change the logical schema without


altering applications.

Physical Data Independence: Ability to change physical storage without


impacting the logical schema.

d) True/False:

1. FALSE – A relation can have only one primary key but multiple
candidate keys.

2. TRUE – Derived attributes are calculated from other attributes.

3. TRUE – SELECT filters rows in relational algebra.

4. FALSE – UNION eliminates duplicates.

5. FALSE – Distributed databases store data across multiple locations.


Question 2: SQL Queries and Relational Algebra

a) Relational Algebra Expression:

Π Title, PubName (σ Price > 500 (BOOK ⋈ PUBLISHER))

b) SQL Query:

SELECT P.PubName, COUNT(B.BookID) AS TotalBooks

FROM PUBLISHER P

JOIN BOOK B ON P.PubID = B.PubID

GROUP BY P.PubName;

c) Tuple Estimation:

1. Π A(X) → 100 tuples (assuming no duplicates).

2. X ⋈ Y → 100 * 200 = 20,000 tuples if Cartesian product.

3. X ∩ Y → Minimum of 100 tuples, assuming compatibility.

4. Σ B > 50 (Y) → Likely half of 200 tuples = 100 tuples.


Question 3: ERD and Relationship Constraints

a) Explanation:

Each employee processes multiple transactions.

Each transaction includes multiple products.

b) Min-Max Notation:

1. EMPLOYEE processes TRANSACTION (1, N).

2. TRANSACTION includes PRODUCT (1, N).

c) Maximum number of records:

50 employees * 200 transactions * 500 products = 5,000,000 records.


d) Relational Schema:

CREATE TABLE EMPLOYEE (

EmpID INT PRIMARY KEY,

Name VARCHAR(50),

Position VARCHAR(50)

);

CREATE TABLE TRANSACTION (

TransID INT PRIMARY KEY,

Date DATE,

EmpID INT,

FOREIGN KEY (EmpID) REFERENCES EMPLOYEE(EmpID)

);

CREATE TABLE PRODUCT (

ProdID INT PRIMARY KEY,

Name VARCHAR(50),

Price DECIMAL(10,2)

);

CREATE TABLE TRANSACTION_DETAILS (

TransID INT,

ProdID INT,

Quantity INT,

PRIMARY KEY (TransID, ProdID),

FOREIGN KEY (TransID) REFERENCES TRANSACTION(TransID),


FOREIGN KEY (ProdID) REFERENCES PRODUCT(ProdID)

);

Question 4: Normalization and Anomalies

a) Highest Normal Form:

The table violates 2NF, as non-key attributes depend partially on composite


keys.

b) Anomalies:

Insertion Anomaly: Adding a new customer without placing an order isn’t


possible.

Deletion Anomaly: Deleting an order deletes customer information.

c) 3NF Decomposition:

CUSTOMER(CustomerID, CustomerName)

PRODUCT(ProductID, ProductName)

ORDER(OrderID, CustomerID, Date)

ORDER_DETAILS(OrderID, ProductID, Quantity)


Would you like further clarification or another set of questions?

Database Systems – Practice Final Exam (Version 4)

Module Title: Database Systems

Module Code: 20CSIC03C

Semester: One

Time Allowed: 2 Hours

Total Marks: 100

Instructions to Students:

Answer ALL questions.

Marks allocation is shown in brackets.

No equipment allowed.

Question 1: Conceptual Understanding [25 Marks]

a) Define and explain the following database concepts: [2 marks each]

i. Super Key

ii. Candidate Key


iii. Weak Entity

v. Referential Integrity

b) Discuss the advantages and disadvantages of normalization in database


design. [7 marks]

d) Determine whether the following statements are TRUE or FALSE


with justification. [10 marks]

i. A relation in 3NF must always be in BCNF.


ii. A composite attribute can have multiple values.
iii. The HAVING clause filters records before grouping them.

iv. The JOIN operation in SQL combines rows based on a related column.

iv. Functional dependency determines how attributes are


related to one another.

Question 2: SQL Queries and Relational Algebra [25 Marks]

Consider the following schema:

STUDENT (StudentID, Name, Age, Major, DeptID)

DEPARTMENT (DeptID, DeptName, Location)

a) Write a relational algebra expression to retrieve student names


and department names for students majoring in ‘CS’. [7 marks]
b) Write an SQL query to retrieve the total number of students in
each department. [6 marks]

c) Given relations M(X, Y) with 120 tuples and N(Y, Z) with 150
tuples, estimate the number of tuples for the following
operations and justify your answer: [12 marks]

M⋈N
i. Π X(M)
ii.
iii. M ∩ N (assuming compatibility)
iv. Σ Y > 50 (N)

Question 3: ERD and Relationship Constraints [30 Marks]

Scenario: A hospital database tracks doctors, patients, and appointments.


Doctors can have multiple appointments, and each patient can have multiple
appointments.

Entities and Attributes:

DOCTOR (DoctorID, Name, Specialization)

PATIENT (PatientID, Name, Age, Gender)

APPOINTMENT (AppointmentID, Date, DoctorID, PatientID)


Relationships:

A DOCTOR can have multiple APPOINTMENTS.

A PATIENT can have multiple APPOINTMENTS.

ER Diagram (Text Representation):

| DOCTOR | | APPOINTMENT | | PATIENT |

| DoctorID (PK) | 1 -- | AppointmentID | -- M | PatientID (PK) |

| Name | | Date | | Name |

| Specialization| | DoctorID (FK) | | Age |

+---------------+ | PatientID (FK) | | Gender |

a) Explain the meaning of the ER diagram based on the given


scenario. [6 marks]

b) Represent the relationship constraints using (min, max) notation.


[8 marks]
c) If there are 50 doctors, 200 patients, and 500 appointments,
what is the maximum number of records in the relationship table
APPOINTMENT? [6 marks]

d) Convert the ER diagram to relational schema including primary


and foreign keys. [10 marks]

Question 4: Normalization and Anomalies [20 Marks]

Consider the following relation storing sales transactions:

Functional Dependencies:

TransactionID → CustomerID, ProductID, Quantity

CustomerID → CustomerName

ProductID → ProductName

a) Identify the highest normal form the relation satisfies and explain
why. [5 marks]

b) Provide an example of an update anomaly and a deletion


anomaly. [7 marks]

c) Normalize the relation to 3NF and provide the decomposed


relations. [8 marks]
Model Answers

Question 1: Conceptual Understanding

a) Definitions:

i. Super Key: A set of attributes that uniquely identify a row in a table.


Example: {StudentID, Name}.

ii. Candidate Key: A minimal super key, meaning no subset can uniquely
identify a row.

iii. Weak Entity: An entity that depends on another entity for identification
and does not have a sufficient unique attribute.

v. Referential Integrity: Ensures foreign key values in one


table match primary key values in another.

b) Advantages and Disadvantages of Normalization:

Advantages:

1. Reduces redundancy.

2. Improves data consistency.

3. Minimizes anomalies.
Disadvantages:

1. Complex queries.

2. Performance overhead due to joins.

3. Increased design complexity.

d) True/False:

1. FALSE – 3NF does not necessarily mean BCNF.

2. FALSE – Composite attributes contain sub-components, not multiple


values.

3. FALSE – HAVING filters groups after aggregation.


4. TRUE – JOIN combines rows based on related keys.

5. TRUE – Functional dependency explains attribute relationships.

Question 2: SQL Queries and Relational Algebra

a) Relational Algebra Expression:

Π Name, DeptName (σ Major = ‘CS’ (STUDENT ⋈ DEPARTMENT))

b) SQL Query:

SELECT D.DeptName, COUNT(S.StudentID) AS TotalStudents

FROM STUDENT S

JOIN DEPARTMENT D ON S.DeptID = D.DeptID

GROUP BY D.DeptName;

c) Tuple Estimation:

1. Π X(M) → 120 tuples.


2. M ⋈ N → 120 * 150 = 18,000 tuples if Cartesian product.

3. M ∩ N → Minimum 120 tuples if fully compatible.

4. Σ Y > 50 (N) → Likely half, around 75 tuples.

Question 3: ERD and Relationship Constraints

a) Explanation:

Doctors schedule multiple appointments, and patients can have multiple


appointments.

b) Min-Max Notation:

1. DOCTOR to APPOINTMENT (1, N)

2. PATIENT to APPOINTMENT (1, N)


c) Maximum records:

50 doctors * 200 patients * 500 appointments = 5,000,000 records.

d) Relational Schema:

CREATE TABLE DOCTOR (

DoctorID INT PRIMARY KEY,

Name VARCHAR(50),

Specialization VARCHAR(50)

);

CREATE TABLE PATIENT (

PatientID INT PRIMARY KEY,

Name VARCHAR(50),

Age INT,

Gender CHAR(1)

);

CREATE TABLE APPOINTMENT (

AppointmentID INT PRIMARY KEY,

Date DATE,

DoctorID INT,

PatientID INT,

FOREIGN KEY (DoctorID) REFERENCES DOCTOR(DoctorID),

FOREIGN KEY (PatientID) REFERENCES PATIENT(PatientID)

);
Would you like another set of questions?

Database Systems – Practice Final Exam (Version 5)

Module Title: Database Systems

Module Code: 20CSIC03C

Semester: One

Time Allowed: 2 Hours

Total Marks: 100

Instructions to Students:

Answer ALL questions.

Marks allocation is shown in brackets.

No equipment allowed.

Question 1: Conceptual Understanding [25 Marks]

a) Define and explain the following database concepts: [2 marks each]


i. Entity Integrity

ii. Outer Join

iii. Specialization in EERD

v. Indexing

b) Describe the differences between a centralized and distributed database


system, highlighting their advantages and disadvantages. [7 marks]

d) Determine whether the following statements are TRUE or FALSE


with justification. [10 marks]

i. A table in BCNF is always in 3NF.


ii. A database view can be used to update data.
iii. In SQL, the GROUP BY clause is used to filter records.

iv. A foreign key must always reference a primary key in another table.

iv. The HAVING clause is used with aggregate functions.

Question 2: SQL Queries and Relational Algebra [25 Marks]

Consider the following schema:

EMPLOYEE (EmpID, Name, Salary, DeptID)

DEPARTMENT (DeptID, DeptName, Location)

a) Write a relational algebra expression to retrieve employee names


and department names for employees earning more than 6000.
[7 marks]
b) Write an SQL query to find the average salary of employees in
each department. [6 marks]

c) Given relations P(A, B) with 200 tuples and Q(B, C) with 300
tuples, estimate the number of tuples for the following
operations and justify your answer: [12 marks]

P⋈Q
i. Π A(P)

P ∪ Q (assuming compatibility)
ii.
iii.
iv. Σ B > 100 (P)

Question 3: ERD and Relationship Constraints [30 Marks]

Scenario: A university wants to track students, courses, and instructors. Each


student can enroll in multiple courses, and each course is taught by one
instructor.

Entities and Attributes:

STUDENT (StudentID, Name, Major)

COURSE (CourseID, Title, Credits, InstructorID)

INSTRUCTOR (InstructorID, Name, Department)


Relationships:

A STUDENT can enroll in multiple COURSES.

Each COURSE is taught by a single INSTRUCTOR.

ER Diagram (Text Representation):

| STUDENT | | COURSE | | INSTRUCTOR |

| StudentID (PK) | M -- | CourseID (PK) | -- 1 | InstructorID (PK)|

| Name | | Title | | Name |

| Major | | Credits | | Department |

+----------------+ | InstructorID (FK) |

a) Explain the meaning of the ER diagram based on the given


scenario. [6 marks]

b) Represent the relationship constraints using (min, max) notation.


[8 marks]
c) If there are 300 students, 50 courses, and 20 instructors, what is
the maximum number of records in the enrollment relationship?
[6 marks]

d) Convert the ER diagram to relational schema including primary


and foreign keys. [10 marks]

Question 4: Normalization and Anomalies [20 Marks]

Consider the following relation storing sales data:

Functional Dependencies:

OrderID → CustomerID, OrderDate

ProductID → ProductName

CustomerID → CustomerName

a) Identify the highest normal form the relation satisfies and explain
why. [5 marks]

b) Provide an example of an update anomaly and an insertion


anomaly. [7 marks]

c) Normalize the relation to 3NF and provide the decomposed


relations. [8 marks]
Model Answers

Question 1: Conceptual Understanding

a) Definitions:

i. Entity Integrity: Ensures each table has a primary key and no null values in
it.

ii. Outer Join: A join that returns matched records as well as unmatched
records from one or both tables.

iii. Specialization in EERD: The process of defining sub-entities with specific


attributes from a general entity.

v. Indexing: A technique used to improve query


performance by reducing the search time for records.

b)

Centralized Database:

All data stored in a single location.

Easier to manage and secure, but prone to bottlenecks.

Distributed Database:
Data distributed across multiple locations.

Improves performance and availability, but increases complexity.

d) True/False:

1. TRUE – BCNF is a stricter form of 3NF.

2. TRUE – Some views are updatable.

3. FALSE – GROUP BY groups records; filtering is done with HAVING.

4. FALSE – A foreign key can reference a unique key as well.

5. TRUE – HAVING is used for filtering groups after aggregation.

Question 2: SQL Queries and Relational Algebra


a) Relational Algebra Expression:

Π Name, DeptName (σ Salary > 6000 (EMPLOYEE ⋈ DEPARTMENT))

b) SQL Query:

SELECT D.DeptName, AVG(E.Salary) AS AvgSalary

FROM EMPLOYEE E

JOIN DEPARTMENT D ON E.DeptID = D.DeptID

GROUP BY D.DeptName;

c) Tuple Estimation:

1. Π A(P) → 200 tuples.

2. P ⋈ Q → 200 * 300 = 60,000 tuples if Cartesian product.

3. P ∪ Q → Maximum 200 tuples if no duplicates.

4. Σ B > 100 (P) → Likely half, around 100 tuples.


Question 3: ERD and Relationship Constraints

a) Explanation:

Students enroll in multiple courses, and each course is taught by one


instructor.

b) Min-Max Notation:

1. STUDENT to COURSE (1, N)

2. COURSE to INSTRUCTOR (1, 1)

c) Maximum records:

300 students * 50 courses = 15,000 records.

d) Relational Schema:

CREATE TABLE STUDENT (

StudentID INT PRIMARY KEY,

Name VARCHAR(50),

Major VARCHAR(50)

);
CREATE TABLE COURSE (

CourseID INT PRIMARY KEY,

Title VARCHAR(50),

Credits INT,

InstructorID INT,

FOREIGN KEY (InstructorID) REFERENCES INSTRUCTOR(InstructorID)

);

CREATE TABLE INSTRUCTOR (

InstructorID INT PRIMARY KEY,

Name VARCHAR(50),

Department VARCHAR(50)

);

CREATE TABLE ENROLLMENT (

StudentID INT,

CourseID INT,

PRIMARY KEY (StudentID, CourseID),

FOREIGN KEY (StudentID) REFERENCES STUDENT(StudentID),

FOREIGN KEY (CourseID) REFERENCES COURSE(CourseID)

);

Would you like another set of questions?


Database Systems – Practice Final Exam (Version 6)

Module Title: Database Systems

Module Code: 20CSIC03C

Semester: One

Time Allowed: 2 Hours

Total Marks: 100

Instructions to Students:

Answer ALL questions.

Marks allocation is shown in brackets.

No additional materials allowed.

Question 1: Conceptual Understanding [25 Marks]

a) Define and explain the following database concepts: [2 marks each]

i. Foreign Key

ii. Trigger

iii. Cardinality in ERD

v. Transaction
b) Describe the advantages of using indexes in a relational database and
mention two types of indexes commonly used. [7 marks]

d) Determine whether the following statements are TRUE or FALSE


with justification. [10 marks]

i. The DELETE statement removes table structure from


the database.
ii. In 2NF, all partial dependencies are eliminated.
iii. SQL functions cannot be used within WHERE clauses.

iv. In a relational model, a tuple refers to a column in a table.

iv. The UNION operation in relational algebra preserves


duplicates.

Question 2: SQL Queries and Relational Algebra [25 Marks]

Consider the following schema:

ORDERS (OrderID, OrderDate, CustomerID, TotalAmount)

CUSTOMER (CustomerID, Name, City)

a) Write a relational algebra expression to retrieve customer names


who placed orders with a total amount greater than 1000. [7
marks]

b) Write an SQL query to retrieve the total number of orders placed


by each customer. [6 marks]
c) Given relations A(P, Q) with 250 tuples and B(Q, R) with 350
tuples, estimate the number of tuples for the following
operations and justify your answer: [12 marks]

A⋈B
i. Π P(A)
ii.
iii. A – B (assuming compatibility)
iv. Σ Q > 50 (A)

Question 3: ERD and Relationship Constraints [30 Marks]

Scenario: A bookstore maintains records of books, authors, and sales


transactions. A book can have multiple authors, and each author can write
multiple books.

Entities and Attributes:

BOOK (BookID, Title, Genre, Price)

AUTHOR (AuthorID, Name, Nationality)

SALE (SaleID, Date, BookID, Quantity, TotalAmount)

Relationships:
A BOOK can have multiple AUTHORS (M:N).

A BOOK can have multiple SALES (1:M).

ER Diagram (Text Representation):

| BOOK | | SALE | | AUTHOR |

| BookID (PK) | 1 -- | SaleID (PK) | | AuthorID (PK) |

| Title | | Date | M --| Name |

| Genre | | Quantity | | Nationality |

| Price | | TotalAmount | +---------------+

+---------------+ | BookID (FK) |

WRITES (BookID, AuthorID)

a) Explain the meaning of the ER diagram based on the given


scenario. [6 marks]

b) Represent the relationship constraints using (min, max) notation.


[8 marks]
c) If there are 200 books, 100 authors, and 300 sales, what is the
maximum number of records in the WRITES relationship? [6
marks]

d) Convert the ER diagram to relational schema including primary


and foreign keys. [10 marks]

Question 4: Normalization and Anomalies [20 Marks]

Consider the following relation storing employee project assignments:

Functional Dependencies:

EmpID → EmpName

ProjectID → ProjectName

(EmpID, ProjectID) → HoursWorked

a) Identify the highest normal form the relation satisfies and explain
why. [5 marks]

b) Provide an example of an insertion anomaly and an update


anomaly. [7 marks]

c) Normalize the relation to 3NF and provide the decomposed


relations. [8 marks]
Model Answers

Question 1: Conceptual Understanding

a) Definitions:

i. Foreign Key: An attribute in one table that refers to the primary key of
another table to establish relationships.

ii. Trigger: A procedural code executed automatically when a specific event


occurs in the database.

iii. Cardinality in ERD: Describes the number of instances of one entity that
can be associated with instances of another entity.

v. Transaction: A sequence of database operations


performed as a single logical unit of work.

b) Advantages of Indexing:

Improves query performance.

Reduces search time.

Types:

1. B-Tree Index
2. Hash Index

d) True/False:

1. FALSE – The DELETE statement removes rows, not the table structure
(DROP does this).

2. TRUE – 2NF removes partial dependencies.

3. FALSE – SQL functions can be used in WHERE.

4. FALSE – A tuple refers to a row.

5. FALSE – UNION removes duplicates by default.

Question 2: SQL Queries and Relational Algebra


a) Relational Algebra Expression:

Π Name (σ TotalAmount > 1000 (ORDERS ⋈ CUSTOMER))

b) SQL Query:

SELECT CustomerID, COUNT(OrderID) AS TotalOrders

FROM ORDERS

GROUP BY CustomerID;

c) Tuple Estimation:

1. Π P(A) → 250 tuples.

2. A ⋈ B → 250 * 350 = 87,500 tuples.

3. A – B → Up to 250 tuples (if no overlap, 0 if full overlap).

4. Σ Q > 50 (A) → Likely half, around 125 tuples.


Question 3: ERD and Relationship Constraints

a) Explanation:

A book can have multiple authors, and an author can write multiple books.

A book can be sold multiple times.

b) Min-Max Notation:

1. BOOK to SALE (1, N)

2. BOOK to AUTHOR (M, N)

c) Maximum records in WRITES:

200 books * 100 authors = 20,000 records.

d) Relational Schema:

CREATE TABLE BOOK (

BookID INT PRIMARY KEY,

Title VARCHAR(100),

Genre VARCHAR(50),
Price DECIMAL(10,2)

);

CREATE TABLE AUTHOR (

AuthorID INT PRIMARY KEY,

Name VARCHAR(100),

Nationality VARCHAR(50)

);

CREATE TABLE SALE (

SaleID INT PRIMARY KEY,

Date DATE,

Quantity INT,

TotalAmount DECIMAL(10,2),

BookID INT,

FOREIGN KEY (BookID) REFERENCES BOOK(BookID)

);

CREATE TABLE WRITES (

BookID INT,

AuthorID INT,

PRIMARY KEY (BookID, AuthorID),

FOREIGN KEY (BookID) REFERENCES BOOK(BookID),

FOREIGN KEY (AuthorID) REFERENCES AUTHOR(AuthorID)

);
Would you like another exam set?

Database Systems – Practice Final Exam (Version 7)

Module Title: Database Systems

Module Code: 20CSIC03C

Semester: One

Time Allowed: 2 Hours

Total Marks: 100

Instructions to Students:

Answer ALL questions.

Marks allocation is shown in brackets.

No additional materials allowed.

Question 1: Conceptual Understanding [25 Marks]

a) Define and explain the following database concepts: [2 marks each]

i. Composite Attribute

ii. Referential Integrity Constraint


iii. Denormalization

v. ACID Properties

b) Compare and contrast static and dynamic SQL. Provide use cases for each.
[7 marks]

d) Determine whether the following statements are TRUE or FALSE


with justification. [10 marks]

i. In 3NF, every non-key attribute must depend on the


primary key directly.
ii. The DISTINCT clause in SQL removes all NULL values
from the results.
iii. In an ER model, a weak entity must always have a
primary key.

iv. The Cartesian product is a type of join operation in relational algebra.

iv. A transaction must always be committed to be


durable.

Question 2: SQL Queries and Relational Algebra [25 Marks]

Consider the following schema:

SUPPLIER (SuppID, Name, City)

PRODUCT (ProdID, ProdName, Price, SuppID)


a) Write a relational algebra expression to retrieve product names
and supplier names for products with a price greater than 200. [7
marks]

b) Write an SQL query to retrieve the number of products supplied


by each supplier located in ‘New York’. [6 marks]

c) Given relations R(A, B) with 300 tuples and S(B, C) with 400
tuples, estimate the number of tuples for the following
operations and justify your answer: [12 marks]

R⋈S
i. Π A®
ii.
iii. R ∩ S (assuming compatibility)
iv. Σ B < 100 ®

Question 3: ERD and Relationship Constraints [30 Marks]

Scenario: A hotel management system tracks guests, rooms, and bookings. A


guest can book multiple rooms, and a room can be booked multiple times.

Entities and Attributes:

GUEST (GuestID, Name, ContactNumber)

ROOM (RoomID, RoomType, PricePerNight)


BOOKING (BookingID, Date, GuestID, RoomID, Duration)

Relationships:

A GUEST can make multiple BOOKINGS.

A ROOM can be booked multiple times.

ER Diagram (Text Representation):

| GUEST | | BOOKING | | ROOM |

| GuestID (PK) | 1 -- | BookingID (PK)| | RoomID (PK) |

| Name | | Date | M --| RoomType |

| ContactNumber | | GuestID (FK) | | PricePerNight |

+---------------+ | RoomID (FK) | +---------------+

| Duration |

a) Explain the meaning of the ER diagram based on the given


scenario. [6 marks]
b) Represent the relationship constraints using (min, max) notation.
[8 marks]

c) If there are 100 guests, 200 rooms, and 500 bookings, what is
the maximum number of records in the BOOKING table? [6
marks]

d) Convert the ER diagram to relational schema including primary


and foreign keys. [10 marks]

Question 4: Normalization and Anomalies [20 Marks]

Consider the following relation storing customer orders:

Functional Dependencies:

OrderID → CustID, ProdID, Quantity

CustID → CustName

ProdID → ProdName

a) Identify the highest normal form the relation satisfies and explain
why. [5 marks]

b) Provide an example of a deletion anomaly and an update


anomaly. [7 marks]
c) Normalize the relation to 3NF and provide the decomposed
relations. [8 marks]

Model Answers

Question 1: Conceptual Understanding

a) Definitions:

i. Composite Attribute: An attribute that can be divided into smaller


meaningful components. Example: Address (Street, City, Zip).

ii. Referential Integrity Constraint: Ensures that a foreign key in one table
references an existing primary key in another table.

iii. Denormalization: The process of combining tables to improve read


performance at the cost of redundancy.

v. ACID Properties: Atomicity, Consistency, Isolation, and


Durability—essential for transaction management in
databases.

b)

Static SQL: SQL statements written and compiled in advance (e.g.,


embedded SQL in applications).

Dynamic SQL: SQL statements built and executed at runtime based on user
inputs or conditions.
Use Cases:

Static SQL: Fixed queries in enterprise applications.

Dynamic SQL: Search functionalities in web applications.

d) True/False:

1. TRUE – 3NF requires no transitive dependencies.

2. FALSE – DISTINCT does not remove NULL values.

3. FALSE – Weak entities rely on a foreign key and discriminator, not a


primary key.

4. TRUE – Cartesian product is a join operation.

5. FALSE – A transaction can be rolled back before being committed.


Question 2: SQL Queries and Relational Algebra

a) Relational Algebra Expression:

Π ProdName, Name (σ Price > 200 (PRODUCT ⋈ SUPPLIER))

b) SQL Query:

SELECT S.Name, COUNT(P.ProdID) AS NumProducts

FROM SUPPLIER S

JOIN PRODUCT P ON S.SuppID = P.SuppID

WHERE S.City = ‘New York’

GROUP BY S.Name;

c) Tuple Estimation:

1. Π A® → 300 tuples.

2. R ⋈ S → 300 * 400 = 120,000 tuples if Cartesian product.

3. R ∩ S → Up to 300 tuples, assuming compatibility.


4. Σ B < 100 ® → Likely half, around 150 tuples.

Question 3: ERD and Relationship Constraints

a) Explanation:

The diagram shows that guests can make multiple bookings, and rooms can
be booked multiple times.

b) Min-Max Notation:

1. GUEST to BOOKING (1, N)

2. ROOM to BOOKING (1, N)

c) Maximum records:

100 guests * 200 rooms = 20,000 records.

d) Relational Schema:
CREATE TABLE GUEST (

GuestID INT PRIMARY KEY,

Name VARCHAR(50),

ContactNumber VARCHAR(15)

);

CREATE TABLE ROOM (

RoomID INT PRIMARY KEY,

RoomType VARCHAR(50),

PricePerNight DECIMAL(10,2)

);

CREATE TABLE BOOKING (

BookingID INT PRIMARY KEY,

Date DATE,

GuestID INT,

RoomID INT,

Duration INT,

FOREIGN KEY (GuestID) REFERENCES GUEST(GuestID),

FOREIGN KEY (RoomID) REFERENCES ROOM(RoomID)

);

Would you like another exam set?

You might also like