Exercise Solutions Available
Step-by-step answers for all textbook questions in this chapter
How to Use This Page
1. Attempt every exercise on your own before reading the solution. 2. Compare your approach with the solution — focus on the logic, not just the final answer. 3. Review the Common Mistakes section to avoid errors that cost marks in exams.
Key Concepts
Database and DBMS
| Concept | Definition |
|---|---|
| Database | Organised collection of related data stored together |
| DBMS | Software that manages creation, manipulation, and retrieval of databases |
| Relational Model | Data organised as tables (relations) with rows (tuples) and columns (attributes) |
| Table / Relation | A set of rows and columns; each row is a record |
| Tuple | A single row in a table (one record) |
| Attribute | A single column in a table (one field) |
| Schema | Structure/blueprint of a database (table names, columns, types) |
| Instance | The actual data in the database at a given time |
Types of Keys
| Key Type | Definition | Example |
|---|---|---|
| Super Key | Any set of attributes that uniquely identifies a tuple | {RollNo}, {RollNo, Name} |
| Candidate Key | A minimal super key (no redundant attribute) | {RollNo}, {Email} |
| Primary Key | The candidate key chosen to identify tuples | RollNo |
| Alternate Key | Candidate keys not selected as primary key | |
| Foreign Key | An attribute in one table referencing the primary key of another table | DeptID in Employee table |
Relational Algebra
| Operation | Symbol | Description | Example |
|---|---|---|---|
| Select | σ | Filters rows by condition | σ_(age>20)(Student) |
| Project | π | Selects specific columns | π_(name,age)(Student) |
| Join | ⋈ | Combines rows from two tables | Student ⋈_(Student.dept=Dept.id) Dept |
Normalisation Forms
| Normal Form | Rule |
|---|---|
| 1NF | Every attribute must have atomic (indivisible) values; no repeating groups |
| 2NF | Must be in 1NF + no partial dependency on a composite primary key |
| 3NF | Must be in 2NF + no transitive dependency (non-key depends only on primary key) |
Multiple Choice Questions (MCQs)
Q1. A DBMS is:
- (a) A hardware device for storing data
- (b) Software for managing databases
- (c) A programming language
- (d) A type of network
Q2. Which key uniquely identifies each record in a table and cannot be null?
- (a) Foreign key
- (b) Candidate key
- (c) Primary key
- (d) Super key
Q3. In relational algebra, the symbol σ (sigma) represents:
- (a) Project operation
- (b) Select operation
- (c) Join operation
- (d) Union operation
Q4. A table is in 2NF if it is in 1NF and:
- (a) It has no foreign keys
- (b) It has no partial dependencies
- (c) It has no transitive dependencies
- (d) It has no duplicate rows
Q5. Which of the following is a transitive dependency?
- (a) RollNo → Name
- (b) RollNo → DeptID → DeptName
- (c) (RollNo, Subject) → Marks
- (d) EmpID → Salary
Fill in the Blanks
Q1. A ______ is a minimal super key.
Q2. The ______ operation in relational algebra selects specific columns from a table.
Q3. In 1NF, every attribute must contain ______ values.
Q4. A ______ key in one table refers to the primary key of another table.
Q5. The process of organising data to reduce redundancy is called ______.
True or False
Q1. A super key can contain redundant attributes.
Q2. A foreign key can have null values.
Q3. A table in 3NF is automatically in 2NF.
Q4. The Project operation in relational algebra can produce duplicate rows.
Q5. In a relational model, data is stored as objects.
Match the Following
| Column A | Column B |
|---|---|
| 1. Primary Key | (a) Removes transitive dependency |
| 2. Foreign Key | (b) Filters rows by condition |
| 3. Select (σ) | (c) Uniquely identifies each tuple |
| 4. Project (π) | (d) References primary key of another table |
| 5. 3NF | (e) Selects specific columns |
Short Answer Questions
Q1. What is a DBMS? Give two examples.
A Database Management System (DBMS) is software that enables users to create, manage, and manipulate databases. It provides tools for storing, retrieving, updating, and deleting data efficiently while ensuring data integrity and security.
Examples: MySQL, PostgreSQL, Oracle, Microsoft SQL Server, SQLite.
Advantages of DBMS:
- Reduces data redundancy
- Ensures data consistency
- Provides data security and access control
- Supports concurrent access by multiple users
- Enables backup and recovery
Q2. Differentiate between primary key and candidate key.
| Feature | Primary Key | Candidate Key |
|---|---|---|
| Definition | Chosen candidate key to identify records | Any minimal set of attributes that uniquely identifies a record |
| Number per table | Only one | Can be multiple |
| Null values | Not allowed | Not allowed |
| Selection | Designer selects one from candidate keys | All minimal super keys are candidate keys |
Example: In a Student table, both RollNo and Email can uniquely identify a student. Both are candidate keys. The designer chooses RollNo as the primary key, making Email an alternate key.
Q3. What is a foreign key? Give an example.
A foreign key is an attribute (or set of attributes) in one table that refers to the primary key of another table. It establishes a relationship between two tables.
Example:
Department Table:
| DeptID (PK) | DeptName |
|---|---|
| D01 | Computer Science |
| D02 | Physics |
Employee Table:
| EmpID (PK) | EmpName | DeptID (FK) |
|---|---|---|
| E1 | Arun | D01 |
| E2 | Bala | D02 |
The DeptID in Employee is a foreign key referencing DeptID in Department. This ensures every employee belongs to a valid department.
Q4. Explain the Select (σ) operation with an example.
The Select operation filters rows from a table based on a condition. It returns all tuples that satisfy the given condition.
Symbol: σ (sigma)
Syntax: σ_condition(Relation)
Example: Given Student table:
| RollNo | Name | Marks |
|---|---|---|
| 101 | Arun | 85 |
| 102 | Bala | 72 |
| 103 | Chitra | 90 |
| 104 | Deepa | 65 |
Query: σ_(Marks>75)(Student)
| RollNo | Name | Marks |
|---|---|---|
| 101 | Arun | 85 |
| 103 | Chitra | 90 |
Q5. Explain the Project (π) operation with an example.
The Project operation selects specific columns from a table, eliminating duplicates in the result.
Symbol: π (pi)
Syntax: π_column_list(Relation)
Example: Using the Student table above:
Query: π_(Name, Marks)(Student)
| Name | Marks |
|---|---|
| Arun | 85 |
| Bala | 72 |
| Chitra | 90 |
| Deepa | 65 |
Detailed Answers
Q1. Explain all types of keys in a database with examples.
Consider a Student table:
| RollNo | RegNo | Name | DeptID | |
|---|---|---|---|---|
| 101 | R2024001 | Arun | [email protected] | D01 |
| 102 | R2024002 | Bala | [email protected] | D02 |
(a) Super Key
Any combination of attributes that uniquely identifies a tuple.
- {RollNo}
- {RollNo, Name}
- {RollNo, RegNo}
- {Email}
- {RegNo, Email}
All of these are super keys because each can uniquely identify a row.
(b) Candidate Key
A minimal super key — removing any attribute would make it non-unique.
- {RollNo} — minimal
- {RegNo} — minimal
- {Email} — minimal
These are candidate keys because they are the smallest sets that still uniquely identify a tuple.
(c) Primary Key
The candidate key chosen by the designer as the main identifier.
- RollNo (chosen as primary key)
(d) Alternate Key
Candidate keys not selected as the primary key.
- RegNo, Email (these are alternate keys)
(e) Foreign Key
An attribute in one table that references the primary key of another table.
- DeptID in Student references DeptID in Department table.
Q2. Explain normalisation with examples (1NF, 2NF, 3NF).
1NF — First Normal Form
Rule: Every attribute must have atomic (indivisible) values. No repeating groups or multi-valued attributes.
Not in 1NF:
| RollNo | Name | Subjects |
|---|---|---|
| 101 | Arun | Maths, Physics, Chemistry |
| 102 | Bala | Biology, Maths |
In 1NF (each subject in a separate row):
| RollNo | Name | Subject |
|---|---|---|
| 101 | Arun | Maths |
| 101 | Arun | Physics |
| 101 | Arun | Chemistry |
| 102 | Bala | Biology |
| 102 | Bala | Maths |
2NF — Second Normal Form
Rule: Must be in 1NF + no partial dependency (every non-key attribute must depend on the entire primary key, not just part of it).
Not in 2NF (composite key: RollNo + Subject):
| RollNo | Subject | Marks | StudentName |
|---|---|---|---|
| 101 | Maths | 85 | Arun |
| 101 | Physics | 78 | Arun |
| 102 | Maths | 90 | Bala |
Problem: StudentName depends only on RollNo (partial dependency), not on the full key (RollNo + Subject).
In 2NF (split into two tables):
Student table:
| RollNo (PK) | StudentName |
|---|---|
| 101 | Arun |
| 102 | Bala |
Marks table:
| RollNo (FK) | Subject | Marks |
|---|---|---|
| 101 | Maths | 85 |
| 101 | Physics | 78 |
| 102 | Maths | 90 |
3NF — Third Normal Form
Rule: Must be in 2NF + no transitive dependency (non-key attributes must not depend on other non-key attributes).
Not in 3NF:
| RollNo (PK) | Name | DeptID | DeptName |
|---|---|---|---|
| 101 | Arun | D01 | Computer Science |
| 102 | Bala | D02 | Physics |
Problem: DeptName depends on DeptID (not directly on RollNo). RollNo → DeptID → DeptName is a transitive dependency.
In 3NF (split into two tables):
Student table:
| RollNo (PK) | Name | DeptID (FK) |
|---|---|---|
| 101 | Arun | D01 |
| 102 | Bala | D02 |
Department table:
| DeptID (PK) | DeptName |
|---|---|
| D01 | Computer Science |
| D02 | Physics |
Q3. Explain the Join operation with an example.
The Join operation combines rows from two tables based on a related column between them.
Student table:
| RollNo | Name | DeptID |
|---|---|---|
| 101 | Arun | D01 |
| 102 | Bala | D02 |
| 103 | Chitra | D01 |
Department table:
| DeptID | DeptName |
|---|---|
| D01 | Computer Science |
| D02 | Physics |
Natural Join: Student ⋈ Department (on DeptID)
| RollNo | Name | DeptID | DeptName |
|---|---|---|---|
| 101 | Arun | D01 | Computer Science |
| 102 | Bala | D02 | Physics |
| 103 | Chitra | D01 | Computer Science |
The join matches rows where DeptID is the same in both tables.
Q4. What are database constraints? Explain different types.
Database constraints are rules enforced on data to maintain accuracy and integrity.
| Constraint | Description | Example |
|---|---|---|
| NOT NULL | Column cannot have null values | Name VARCHAR(50) NOT NULL |
| UNIQUE | Column values must be unique | Email VARCHAR(100) UNIQUE |
| PRIMARY KEY | Unique + Not Null identifier | RollNo INT PRIMARY KEY |
| FOREIGN KEY | References primary key of another table | DeptID VARCHAR(5) REFERENCES Dept(DeptID) |
| CHECK | Values must satisfy a condition | Marks INT CHECK (Marks >= 0 AND Marks <= 100) |
| DEFAULT | Provides a default value if none specified | Status VARCHAR(10) DEFAULT 'Active' |
CREATE TABLE Student (
RollNo INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Email VARCHAR(100) UNIQUE,
DeptID VARCHAR(5),
Marks INT CHECK (Marks >= 0 AND Marks <= 100),
Status VARCHAR(10) DEFAULT 'Active',
FOREIGN KEY (DeptID) REFERENCES Department(DeptID)
);
Q5. Differentiate between file system and DBMS.
| Feature | File System | DBMS |
|---|---|---|
| Data redundancy | High (data duplicated) | Low (centralised storage) |
| Data consistency | Low | High |
| Data sharing | Difficult | Easy (concurrent access) |
| Security | Limited | Comprehensive |
| Backup and recovery | Manual | Automatic |
| Data independence | Not present | Present (physical and logical) |
| Query support | Limited | Powerful (SQL) |
| Integrity constraints | Not enforced | Enforced |
| Example | Spreadsheets, text files | MySQL, PostgreSQL, Oracle |
Q6. Explain the relational model with an example.
The relational model represents data as a collection of relations (tables). Each relation has:
- Relation name (table name)
- Attributes (column names)
- Tuples (rows/records)
- Domain (set of allowed values for each attribute)
Example: Student Relation
Schema: Student(RollNo, Name, Age, DeptID)
Instance (data):
| RollNo | Name | Age | DeptID |
|---|---|---|---|
| 101 | Arun | 17 | D01 |
| 102 | Bala | 18 | D02 |
| 103 | Chitra | 17 | D01 |
Properties:
- Each column has a unique name (attribute name)
- Each cell contains a single atomic value
- No duplicate rows (tuples are unique)
- Order of rows and columns is not significant
- Each row is unique, identifiable by primary key
Q7. Write SQL queries to create tables with primary and foreign keys.
-- Department table
CREATE TABLE Department (
DeptID VARCHAR(5) PRIMARY KEY,
DeptName VARCHAR(50) NOT NULL,
HOD VARCHAR(50)
);
-- Student table with foreign key
CREATE TABLE Student (
RollNo INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Age INT CHECK (Age > 0),
Email VARCHAR(100) UNIQUE,
DeptID VARCHAR(5),
FOREIGN KEY (DeptID) REFERENCES Department(DeptID)
);
-- Insert data
INSERT INTO Department VALUES ('D01', 'Computer Science', 'Dr. Kumar');
INSERT INTO Department VALUES ('D02', 'Physics', 'Dr. Lakshmi');
INSERT INTO Student VALUES (101, 'Arun', 17, '[email protected]', 'D01');
INSERT INTO Student VALUES (102, 'Bala', 18, '[email protected]', 'D02');
INSERT INTO Student VALUES (103, 'Chitra', 17, '[email protected]', 'D01');
Common Mistakes
| Mistake | Why It's Wrong | Correction |
|---|---|---|
| Confusing primary key and candidate key | Primary key is one chosen candidate key | All minimal unique identifiers are candidate keys; designer picks one as primary |
| Saying 3NF does not require 2NF | 3NF builds on 2NF | 3NF = 2NF + no transitive dependencies |
| Allowing null in primary key | Primary key must be unique and NOT NULL | Primary key columns cannot have null values |
| Confusing Select (σ) and Project (π) | Select filters rows, Project selects columns | σ filters rows; π selects columns |
| Thinking foreign key must be unique | Foreign key values can repeat | Multiple employees can belong to the same department |
| Ignoring partial dependency in 2NF | Non-key attributes must depend on entire PK | In composite key tables, each non-key attribute must depend on ALL key attributes |
| Confusing super key and candidate key | Super key may have redundant attributes | Candidate key is a minimal super key |
Exam Checklist
- [ ] I can define database, DBMS, and relational model
- [ ] I can differentiate between super key, candidate key, primary key, alternate key, and foreign key
- [ ] I can perform Select (σ) and Project (π) operations on a given table
- [ ] I can perform Join operations between two tables
- [ ] I can explain 1NF, 2NF, and 3NF with examples
- [ ] I can identify partial and transitive dependencies
- [ ] I know the six database constraints: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT
- [ ] I can write SQL CREATE TABLE statements with constraints
- [ ] I can convert unnormalised data to 1NF, 2NF, and 3NF
