# Database Management Systems | Set 1

Following questions have been asked in GATE CS exam.

**1. Given the relations**

*employee (name, salary, deptno)* and

*department (deptno, deptname, address)*

**Which of the following queries cannot be expressed using the basic relational algebra
operations (U, -, x, π, σ, p)? (GATE CS 2000)**

(a) Department address of every employee

(b) Employees whose name is the same as their department name

(c) The sum of all employees’ salaries

(d) All employees of a given department

**Answer:** (c)

**Explanation:**

The six basic operators of relational algebra are the selection(σ ), the projection(π), the Cartesian product (x) (also called the cross product or cross join), the set union (U), the set difference (-), and the rename (p). These six operators are fundamental in the sense that none of them can be omitted without losing expressive power. Many other operators have been defined in terms of these six. Among the most important are set intersection, division, and the natural join, but aggregation is not possible with these basic relational algebra operations. So, we cannot run sum of all employees’ salaries with the six operations.

**References:**

http://en.wikipedia.org/wiki/Relational_algebra

http://faculty.ksu.edu.sa/zitouni/203%20Haseb%20%20Lecture%20Notes/Relional%20Algebra.pdf

2. Given the following relation instance.

x y z 1 4 2 1 5 3 1 6 3 3 2 2

**Which of the following functional dependencies are satisfied by the instance? (GATE CS 2000)**

(a) XY -> Z and Z -> Y

(b) YZ -> X and Y -> Z

(c) YZ -> X and X -> Z

(d) XZ -> Y and Y -> X

**Answer:** (b)

**Explanation:**

A functional dependency (FD) is a constraint between two sets of attributes in a relation from a database. A FD X->Y require that the value of X uniquely determines the value of Y where X and Y are set of attributes. FD is a generalization of the notion of a key.

Given that X, Y, and Z are sets of attributes in a relation R, one can derive several properties of functional dependencies. Among the most important are Armstrong’s axioms, which are used in database normalization:

* Subset Property (Axiom of Reflexivity): If Y is a subset of X, then X ? Y * Augmentation (Axiom of Augmentation): If X -> Y, then XZ -> YZ * Transitivity (Axiom of Transitivity): If X -> Y and Y -> Z, then X -> Z

From these rules, we can derive these secondary rules:

* Union: If X -> Y and X -> Z, then X -> YZ * Decomposition: If X -> YZ, then X -> Y and X -> Z * Pseudotransitivity: If X -> Y and YZ -> W, then XZ -> W

In the above question, Y uniquely determines X and Z, for a given value of Y you can easily find out values of X and Z.

So, Y -> X and Y -> Z hold for above schema.

From rule of augmentation we can say YZ->X. If we understand the notion of FD, we don’t need to apply axioms to find out which option is true, just by looking at the schema and options we can say that (b) is true.

**References:**

http://www.cse.iitb.ac.in/~sudarsha/db-book/slide-dir/ch7.pdf

http://en.wikipedia.org/wiki/Functional_dependency

3. Given relations r(w, x) and s(y, z), the result of

*select distinct w, x
from r, s*

is guaranteed to be same as r, provided (GATE CS 2000)

(a) r has no duplicates and s is non-empty

(b) r and s have no duplicates

(c) s has no duplicates and r is non-empty

(d) r and s have the same number of tuples

**Answer:** (a)

**Explanation:**

The query selects all attributes of r. Since we have distinct in query, result can be equal to r only if r doesn’t have duplicates.

If we do not give any attribute on which we want to join two tables, then the queries like above become equivalent to Cartesian product. Cartisian product of two sets will be empty if any of the two sets is empty. So, s should have atleast one record to get all rows of r.

4. In SQL, relations can contain null values, and comparisons with null values are treated as unknown. Suppose all comparisons with a null value are treated as false. Which of the

following pairs is not equivalent? (GATE CS 2000)

(a) x = 5, not (not (x = 5)

(b) x = 5, x > 4 and x < 6, where x is an integer

(c) x < 5, not(x = 5)

(d) None of the above

**Answer** (c)

**Explanation:**

It doesn’t need much explanation. For all values smaller than 5, x < 5 will always be true but x = 5 will be false.

5. Consider a schema R(A, B, C, D) and functional dependencies A -> B and C -> D. Then the decomposition of R into R1 (A, B) and R2(C, D) is (GATE CS 2001)

a) dependency preserving and loss less join

b) loss less join but not dependency preserving

c) dependency preserving but not loss less join

d) not dependency preserving and not loss less join

**Answer:** (c)

**Explanation:**

**Dependency Preserving Decomposition:**

Decomposition of R into R1 and R2 is a dependency preserving decomposition if closure of functional dependencies after decomposition is same as closure of FDs before decomposition.

A simple way is to just check whether we can derive all the original FDs from the FDs present after decomposition.

In the above question R(A, B, C, D) is decomposed into R1 (A, B) and R2(C, D) and there are only two FDs A -> B and C -> D. So, the decomposition is dependency preserving

**Lossless-Join Decomposition:**

Decomposition of R into R1 and R2 is a lossless-join decomposition if at least one of the following functional dependencies are in F+ (Closure of functional dependencies)

R1 ∩ R2 → R1 OR R1 ∩ R2 → R2

In the above question R(A, B, C, D) is decomposed into R1 (A, B) and R2(C, D), and R1 ∩ R2 is empty. So, the decomposition is not lossless.

**References:**

http://www.cs.sfu.ca/CC/354/han/materia/notes/354notes-chapter6/node1.html

## Recommended Posts:

- Database Management Systems | Set 6
- Database Management Systems | Set 3
- Database Management Systems | Set 4
- Database Management Systems | Set 5
- Database Management Systems | Set 7
- Database Management Systems | Set 10
- Database Management Systems | Set 8
- Database Management Systems | Set 9
- Database Management Systems | Set 11
- Database Management Systems | Set 2
- Perl | Database management using DBI
- SQL Trigger | Book Management Database
- Introduction of DBMS (Database Management System) | Set 1
- Personnel involved in Database Management System
- Data Management issues in Mobile database