CT 2 Solutions
CT 2 Solutions
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;
These functions are often used with the GROUP BY clause to perform operations on groups
of rows.
Functions of Normalization:
- Removes duplicate data
- Ensures logical data storage
- Improves consistency
- Enhances query performance
Normal Forms:
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.
7. Join (⨝): Combines related tuples from two relations based on a condition.
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.
- 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.