DBMS Tutorial - 2 Solutions Final
DBMS Tutorial - 2 Solutions Final
ii) Relation Schema: A relation schema R, denoted by R(A1, A2, ...,An)is made up of a relation name R and a
list of attributes A1, A2, ...,An. A relation schema is used to describe a relation where R is called the
name of this relation.
Ex:
iii) Domain: A domain D is a set of atomic values. Atomic means that each value in the domain is indivisible
as far as the formal relational model is concerned.
Ex:
iv) Arity: The degree or Arity of a relation is the number of attributes in a relation schema.
Ex:
v) Check Constraint:
Check constraints enforce specific conditions that each row must satisfy. This can involve comparisons or
logical operations.
Check Constraint: It specifies a condition that must be true for every row in the table.
i) SELECT ():
The SELECT operation acts as a filter, it is used to extract a subset of tuples or rows from a relation based on
a “selection condition”.
It returns or displays only those tuples that satisfy the qualifying condition, remaining tuples are discarded.
The number of tuples in the result of a SELECT operation is less than or equal to the number of tuples in the
input relation R.
It is denoted by Greek symbol “Sigma - ”
Syntax: <selection condition>(R)
ii) PROJECT ():
The PROJECT operation acts as a filter, it is used to extract a subset of Attributes or Columns from a relation
based on “attribute list”.
It returns or displays only those attributes that are given in the attribute list, remaining attributes are discarded.
The number of attributes in the result of a PROJECT operation is less than or equal to the number of tuples in
the input relation R.
It removes any duplicate entries and displays only once.
It is denoted by Greek symbol “Pi - ”
Syntax: <attribute list>(R)
iii) RENAME ():
The RENAME operation is used to rename the attributes or table or both.
It renames the input relation attributes or relation name as provided by the user.
It is denoted by Greek symbol “Rho - ”
Syntax: S(B1, B2, …, Bn)(R) or S(R) or (B1, B2, …, Bn)(R)
SELECT: DEPT=HR(EMPLOYEE)
EMPLOYEE
EID ENAME AGE DEPT SALARY
1001 Alice 30 HR 50000
1003 Charles 28 HR 40000
RENAME: EMP(EMPLOYEE)
The above query will rename the EMPLOYEE table as EMP
5) Discuss the various types of Join operations with an example. Why theta join is required.
Soln:
In relational databases, join operations are used to combine rows from two or more tables based on a related column
between them. There are several types of join operations, each serving different purposes and producing different results.
The various types of join operations along with examples are as follows:
Department
Did Dname
101 HR
102 IT
104 Finance
i) Inner Join:
The inner join returns only the rows that matches the given condition values in both tables.
Ex: Department Employee.Did=Departments.DidEmployee
Eid Ename Dname
1001 Alice HR
1002 Bob IT
vi) EQUIJOIN:
The join operation where only = operator is used is called EQUIJOIN.
In the result of EQUIJOIN we always have one or more pairs of attributes that have identical value.
Ex:
ii) Super Key: A super key is a set of one or more attributes that, taken collectively, uniquely identify a tuple in a
relation. A super key may contain additional attributes that are not necessary for unique identification (i.e., it
may have redundant attributes).
iii) Candidate Key: A candidate key is a minimal super key, meaning it is a super key with no redundant attributes. In
other words, it is a set of attributes that uniquely identify a tuple, and no subset of these attributes can uniquely
identify a tuple.
iv) Primary Key: A primary key is a candidate key that is chosen by the database designer to uniquely identify tuples
in a relation. It must contain unique values and cannot contain null values. Each table can have only one primary
key.
v) Foreign Key: A foreign key is an attribute or a set of attributes in one table that refers to the primary key in another
table. The foreign key establishes a relationship between the two tables, ensuring that the value in the foreign
key column(s) corresponds to a valid value in the referenced primary key column(s).
7) Explain with an example the violation of the integrity constraint in each of the three types of update operations.
Soln:
Consider two tables Employee and Department,
Employee Department
Eid Ename Did Did Dname
1001 Alice 101 101 HR
1002 Bob 102 102 IT
1003 Charles 103 104 Finance
i) Insert Operation:
Violation of Entity Integrity: Entity integrity ensures that the primary key of a table must be unique and not
null.
Example: If we attempt to insert a row with a null value in the `EmployeeID` column, it violates the entity
integrity constraint.
INSERT INTO Employee (Eid, Ename, Did) VALUES (NULL, 'David', 104);
This insert operation will fail because the primary key cannot be null.
Violation of Referential Integrity: Referential integrity ensures that a foreign key value must match a
primary key value in another table or be null.
Example: If we insert a row into `Employees` with a `DepartmentID` that doesn't exist in the `Departments`
table, it violates referential integrity.
INSERT INTO Employees (Eid, Ename, Did) VALUES (1004, 'David', 999);
This insert operation will fail because `DepartmentID` 999 does not exist in the `Departments` table.