DBMS Theoretical Exam Answers
Q1: Explain various kinds of join operation (natural join, outer join, equi
join).
Join operations in DBMS are used to combine rows from two or more tables based on a
related column.
1. Natural Join:
It combines two tables based on all columns with the same name and data type. Duplicate
columns are eliminated.
Example:
SELECT * FROM Employee NATURAL JOIN Department;
2. Equi Join:
It combines rows from two tables based on a specified condition using the equality
operator (=). The result includes all columns from both tables.
Example:
SELECT * FROM Employee E, Department D WHERE E.dept_id = D.dept_id;
3. Outer Join:
Outer joins return matching rows and also the non-matching rows from one or both
tables.
- Left Outer Join: Returns all rows from the left table and matched rows from the right.
- Right Outer Join: Returns all rows from the right table and matched rows from the left.
- Full Outer Join: Returns all rows from both tables with NULLs for unmatched rows.
Example:
SELECT * FROM Employee LEFT OUTER JOIN Department ON Employee.dept_id =
Department.dept_id;
Q2: Explain various types of SQL aggregate functions.
SQL aggregate functions perform calculations on a set of values and return a single value.
Common types include:
1. COUNT(): Returns the number of rows.
SELECT COUNT(*) FROM Employees;
2. SUM(): Returns the total sum of a numeric column.
SELECT SUM(Salary) FROM Employees;
3. AVG(): Returns the average value of a numeric column.
SELECT AVG(Salary) FROM Employees;
4. MIN(): Returns the minimum value in a column.
SELECT MIN(Salary) FROM Employees;
5. MAX(): Returns the maximum value in a column.
SELECT MAX(Salary) FROM Employees;
These functions are often used with the GROUP BY clause to perform operations on groups
of rows.
Q3: Explain the function of normalization. Briefly explain various normal
form with example.
Normalization is the process of organizing data in a database to reduce redundancy and
improve data integrity.
Functions of Normalization:
- Removes duplicate data
- Ensures logical data storage
- Improves consistency
- Enhances query performance
Normal Forms:
1. First Normal Form (1NF):
Ensures that the table has atomic (indivisible) values and each column contains unique
data.
Example: A column with multiple phone numbers violates 1NF.
2. Second Normal Form (2NF):
Based on 1NF and removes partial dependency; every non-prime attribute is fully
functionally dependent on the whole primary key.
Example: In a table with composite key (RollNo, Subject), storing StudentName violates
2NF.
3. Third Normal Form (3NF):
Based on 2NF and removes transitive dependency; non-prime attributes should not
depend on other non-prime attributes.
Example: If Student table has (RollNo, Name, Dept, HOD), and HOD depends on Dept, then
it's not in 3NF.
Q4: What are various types of relational algebra?
Relational algebra is a procedural query language used to retrieve data from a relational
database. Its main types are:
1. Selection (σ): Selects rows that satisfy a given condition.
σ(condition)(Relation)
2. Projection (π): Selects specific columns from a relation.
π(column1, column2)(Relation)
3. Union (∪): Combines tuples from two relations and removes duplicates.
4. Set Difference (−): Returns tuples that are in one relation but not in the other.
5. Cartesian Product (×): Combines every tuple of one relation with every tuple of another.
6. Rename (ρ): Renames the output relation or its attributes.
7. Join (⨝): Combines related tuples from two relations based on a condition.
These operations form the basis for queries in relational databases.
Q5: Explain various key. Explain association, aggregation.
Types of Keys in DBMS:
1. Primary Key: Uniquely identifies each record in a table. Cannot be NULL.
2. Candidate Key: A set of attributes that can uniquely identify a record. Primary key is
chosen from candidate keys.
3. Super Key: A set of one or more attributes that uniquely identify a record.
4. Foreign Key: An attribute in one table that refers to the primary key of another table.
5. Composite Key: A primary key made up of two or more attributes.
Association and Aggregation:
- Association:
It is a relationship between two entities. For example, a student enrolls in a course.
- Aggregation:
A specialized form of association where a relationship is treated as a higher-level entity. It
represents a “whole-part” relationship.
Example: A project is associated with multiple departments. The “works-on” relationship
between employee and project can be aggregated.