GATE Ques Set 2
GATE Ques Set 2
GATE Ques Set 2
in/cs/Syllabus/Computer-Science-Information-Technology/Databases/Relational-
model-relational-algebra-tuple-calculus
Q1: Consider the following relations P(X,Y,Z), Q(X,Y,T) and R(Y,V). (GATE 2019-2)
P
X Y Z
X1 Y1 Z1
X1 Y1 Z2
X2 Y2 Z2
X2 Y4 Z4
Q
X Y T
X2 Y1 2
X1 Y2 5
X1 Y1 6
X3 Y3 1
R
Y V
Y1 V1
Y3 V2
Y2 V3
Y2 V2
How many tuples will be returned by the following relational algebra query?
∏X(σ(P.Y=R.Y∧R.V=V2)(P×R))−∏X(σ(Q.Y=R.Y∧Q.T>2)(Q×R))
Answer: 1
Q2: Consider the relations r(A, B) and s(B, C), where s.B is a primary key and r.B is a foreign key
referencing s.B. Consider the query (GATE 2018-2)
Q: r⋈(σB<5(S))
Let LOJ denote the natural left outer-join operation. Assume that r and s contain no null values.
A) σB<5(r⋈S)
B) σB<5(r LOJ s)
C) r LOJ(σB<5(s))
D) σB<5(r) LOJ s
Answer: C
Q3: Consider a database that has the relation schems EMP (Empld, EmpName, DeptId),
and DEPT (DeptName, DeptId). Note that the DeptId can be permited to be NULL in the
relation EMP. Consider the following queries on the database expressed in tuple relational calculus.
(GATE 2017-2)
(I){t|∃u∈EMP(t[EmpName]=u[EmpName]∧∀v∈DEPT(t[DeptId]≠v[DeptId]))}
(II){t|∃u∈EMP(t[EmpName]=u[EmpName]∧∃v∈DEPT(t[DeptId]≠v[DeptId]))}
(III){t|∃u∈EMP(t[EmpName]=u[EmpName]∧∃v∈DEPT(t[DeptId]=v[DeptId]))}
A) I & II only
D) I, II & III
Answer: D
Q4: Consider a database that has the relation schema CR (StudentName, CourseName).An instance of
the schema CR is as given below. (GATE 2017-2)
CR
StudentName CourseName
SA CA
SA CB
SA CC
SB CB
SB CC
SC CA
SC CB
SC CC
SD CA
SD CB
SD CC
SD CD
SE CD
SE CA
SE CB
SF CA
SF CB
SF CC
T1←πCourseName(σStudentName=′SA′(CR))T2←CR÷T1
The number of rows in T2 is__________
Answer: 4
Q5: SELECT operation in SQL is equivalent to (GATE 2015-1)
Answer: D
Q6: Consider two relations R1(A,B) with the tuples(1, 5), (3, 7) and R2(A, C) = (1, 7), (4, 9). Assume
that R(A,B,C) is the full natural outer join of R1 and R2. Consider the following tuples of the form
(A, B, C): a =(1, 5, null), b =(1, null, 7), c = (3, null, 9), d = (4, 7, null), e = (1, 5, 7), f = (3,
7, null), g = (4, null, 9). Which one of the following statements is correct? (GATE 2015-2)
B) R contains all of a, b, c, d, e, f, g.
Answer: C
Q7: Consider a join (relation algebra) between relations r(R) and s(S) using the nested loop method.
There are 3 buffers each of size equal to disk block size, out of which one buffer is reserved for
intermediate results. Assuming size (r(R))<size(s(S)), the join will have fewer number of disk block
accesses if (GATE 2014-2)
Answer: A
πA1(πA2(σF1(σF2(r)))), where A1, A2 are sets of attributes in r with A1 ⊂ A2 and F1, F2 are Boolean
expressions based on the attributes in r? (GATE 2014-1)
A) πA1(σ(F1ΛF2)(r))
B) πA1(σ(F1∨F2)(r))
C) πA2(σ(F1∧F2)(r))
D) πA2(σ(F1∨F2)(r))
Answer: A
Q9: Consider the relational schema given below, where eId of the relation dependent is a foreign key
referring to empId of the relation employee. Assume that every employee has at least one
associated dependent in the dependent relation. (GATE 2014-2)
πempId(employee)−πempId(employee⋈(empId=eID)∧(empAge≤depAge)Dependent)
The above query evaluates to the set of empIds of employees whose age is greater than that of
A) some dependent.
B) all dependents
C) some of his/her dependents
D) all of his/her dependents.
Answer: D
(II) ∏sname(σcourseno=107∧percent>90(Registration⋈Students)
(IV) {<SN> | ∃SR ∃RP ( <SR, SN>∈∈ Students ∧ <SR, 107, RP>∈∈ Registration ∧ RP>90)}
A) I, II, III and IV B) I, II and III only C) I, II and IV only D) II, III and IV only
Answer: A
Q11: Suppose R1(A, B) and R2(C, D) are two relation schemas. Let r1 and r2 be the corresponding
relation instances. B is a foreign key that refers to C in R 2. If data in r1 and r2 satisfy referential
integrity constraints, which of the following is ALWAYS TRUE? (GATE 2012-2)
A) ΠB(r1)−ΠC(r2)=∅
B) ΠC(r2)−ΠB(r1)=∅
C) ΠB(r1)=ΠC(r2)
D) ΠB(r1)−ΠC(r2)≠∅
Answer: A
Q12: Consider a relational table with a single record for each registered student with the following
attributes. (GATE 2011-1)
2. UID: Unique identity number, unique at the national level for each citizen
3. BankAccount_Num: Unique account number at the bank. A student can have multiple accounts or
joint accounts. This attribute stores the primary account number.
C) UID is a candidate key if all students are from the same country
Answer: A
Q13: Consider a relational table r with sufficient number of records, having attributes A1, A2,……
An and let 1 ≤ p ≤ n. Two queries Q1 and Q2 are given below. (GATE 2011-2)
Answer: C
Q14: Let R and S be relational schemes such that R={a,b,c} and S={c}. Now consider the following
queries on the database: (GATE 2009-2)
I. πR−S(r)−πR−S(πR−S(r)×S−πR−S,S(r))
II. {t|t∈πR−S(r)∧∀u∈s(∃v∈r(u=v[s]∧t=v[R−S]))}
III. {t|t∈πR−S(r)∧∀v∈r(∃u∈s(u=v[s]∧t=v[R−S]))}
IV. Select R.a, R.b from R, S where R.c = S.c
A) I & II
B) I & III
C) II & IV
D) III & IV
Answer: C
SELECT S.sname
FROM Suppliers S
WHERE S.sid NOT IN (SELECT C.sid
FROM Catalog C
WHERE C.pid NOT (SELECT P.pid
FROM Parts P
WHERE P.color<> 'blue'))
Assume that relations corresponding to the above schema are not empty. Which one of the following
is the correct interpretation of the above query?
A) Find the names of all suppliers who have supplied a non-blue part.
B) Find the names of all suppliers who have not supplied a non-blue part.
C) Find the names of all suppliers who have supplied only blue parts.
D) Find the names of all suppliers who have not supplied only blue parts.
Answer: A
I. ¬∃t∈r(P(t))
II.∃t∉r(P(t))
IV. ∃t∉r(¬P(t))
III. ¬∃t∈r(¬P(t))
Answer: D
Q17: Let R and S be two relations with the following schema (GATE 2008-2)
R (P,Q.R1,R2,R3)
S (P,Q,S1,S2)
Where {P, Q} is the key for both schemas. Which of the following queries are equivalent?
I. ∏p (R ⋈ S)
II. ∏p (R) ⋈∏p (S)
III. ∏p (∏p, Q (R) ∩ ∏ p, Q (S))
IV. ∏p (∏p, Q (R) - (∏p, Q (R) - ∏ p, Q (S))
A) Only I and II B) Only I and III C) Only I, II and III D) Only I , III and IV
Answer: D
Q18: Information about a collection of students is given by the relation studInfo(studId, name, sex).
The relation enroll(studId, courseId) gives which student has enrolled for (or taken) what course(s).
Assume that every course is taken by at least one male and at least one female student. What does the
following relational algebra expression represent? (GATE 2007-2)
∏courseId((∏studId(σsex="female"(studInfo))×∏courseId(enroll))−enroll)
Answer: B
Q19: Consider the relation employee(name, sex, supervisorName) with name as the
key. supervisorName gives the name of the supervisor of the employee under consideration. What
does the following Tuple Relational Calculus query produce? (GATE 2007-2)
Answer: B
https://www.geeksforgeeks.org/database-management-system-set-1/
Q20: 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)
Q22: 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)
https://www.geeksforgeeks.org/database-management-system-set-2/
Q23: Which of the following statements are TRUE about an SQL query? (GATE 2012)
P: An SQL query can contain a HAVING clause even if it does not a GROUP BY clause
Q: An SQL query can contain a HAVING clause only if it has a GROUP BY clause
R: All attributes used in the GROUP BY clause must appear in the SELECT clause
S: Not all attributes used in the GROUP BY clause need to appear in the SELECT clause
(A) P and R
(B) P and S
(C) Q and R
(D) Q and S
Answer (C)
https://www.geeksforgeeks.org/database-management-system-set-3/
Q24: Consider the following relations A, B, C. How many tuples does the result of the
following relational algebra expression contain? Assume that the schema of A U B is the same
as that of A. (GATE 2012)
Table A
Id Name Age
----------------
12 Arun 60
15 Shreya 24
99 Rohit 11
Table B
Id Name Age
----------------
15 Shreya 24
25 Hari 40
98 Rohit 20
99 Rohit 11
Table C
Id Phone Area
-----------------
10 2200 02
99 2100 01
(A) 7
(B) 4
(C) 5
(D) 9
Answer (A)
Q25: Consider the above tables A, B and C. How many tuples does the result of the following
SQL query contains? (GATE 2012)
SELECT A.id
FROM A
WHERE A.age > ALL (SELECT B.age
FROM B
WHERE B. name = "arun")
(A) 4
(B) 3
(C) 0
(D) 1
Answer (B)
https://www.geeksforgeeks.org/database-management-systems-set-4/
Q26: Database table by name Loan_Records is given below. (GATE 2011)
Borrower Bank_Manager Loan_Amount
Ramesh Sunderajan 10000.00
Suresh Ramgopal 5000.00
Mahesh Sunderajan 7000.00
What is the output of the following SQL query?
SELECT Count(*)
FROM ( (SELECT Borrower, Bank_Manager
FROM Loan_Records) AS S
NATURAL JOIN (SELECT Bank_Manager,
Loan_Amount
FROM Loan_Records) AS T );
(A) 3
(B) 9
(C) 5
(D) 6
Answer (C)
Q27: Consider a database table T containing two columns X and Y each of type integer. After
the creation of the table, one record (X=1, Y=1) is inserted in the table.
Let MX and My denote the respective maximum values of X and Y among all records in the
table at any point in time. Using MX and MY, new records are inserted in the table 128 times
with X and Y values being MX+1, 2*MY+1 respectively. It may be noted that each time after
the insertion, values of MX and MY change. What will be the output of the following SQL
query after the steps mentioned above are carried out? (GATE 2011)
SELECT Y FROM T WHERE X=7;
(A) 127
(B) 255
(C) 129
(D) 257
Answer (A)
https://www.geeksforgeeks.org/database-management-systems-set-5/
Q28: A relational schema for a train reservation database is given below. (GATE 2010)
Passenger (pid, pname, age)
Reservation (pid, class, tid)
Table: Passenger
pid pname age
-----------------
0 Sachin 65
1 Rahul 66
2 Sourav 67
3 Anil 69
Table : Reservation
pid class tid
---------------
0 AC 8200
1 AC 8201
2 SC 8201
5 AC 8203
1 SC 8204
3 AC 8202
What pids are returned by the following SQL query for the above instance of the tables?
SLECT pid
FROM Reservation,
WHERE class ‘AC’ AND
EXISTS (SELECT *
FROM Passenger
WHERE age > 65 AND
Passenger. pid = Reservation.pid)
(A) 1, 0
(B) 1, 2
(C) 1, 3
(S) 1, 5
Answer (C)
https://www.geeksforgeeks.org/database-management-systems-set-8/
Q29: The following table has two attributes A and C where A is the primary key and C is the
foreign key referencing A with on-delete cascade. (GATE 2005)
A C
-----
2 4
3 4
4 3
5 2
7 2
9 5
6 4
The set of all tuples that must be additionally deleted to preserve referential integrity when
the tuple (2,4) is deleted is:
(a) (3,4) and (6,4)
(b) (5,2) and (7,2)
(c) (5,2), (7,2) and (9,5)
(d) (3,4), (4,3) and (6,4)
Answer (C)
Q30: The relation book (title, price) contains the titles and prices of different books. Assuming
that no two books have the same price, what does the following SQL query list? (GATE 2005)
select title
from book as B
where (select count(*)
from book as T
where T.price > B.price) < 5
(a) Titles of the four most expensive books
(b) Title of the fifth most inexpensive book
(c) Title of the fifth most expensive book
(d) Titles of the five most expensive books
Answer (d)
https://www.geeksforgeeks.org/isro-cs-2020/
A cannot be performed to retrieve the lost data, while ‘DELETE’ allow it.
After the execution of ‘DELETE’ and ‘TRUNCATE’ operation retrieval is easily possible
After the execution of ‘DELETE’ operation, COMMIT and ROLLBACK statements can
C be performed to retrieve the lost data, while TRUNCATE do not allow it.
After the execution of ‘DELETE’ and ‘TRUNCATE’ operation no retrieval is possible for
Answer: C
https://www.geeksforgeeks.org/isro-cs-2018/
Q33: Consider the set of relations given below and the SQL query that follows
C Sriram
SELECT DISTINCT w, x
FROM R, S
Is guaranteed to be same as R, if
A R has no duplicates and S is non-empty
https://www.geeksforgeeks.org/isro-cs-2017-may/
Q35:
https://www.geeksforgeeks.org/isro-cs-2017/
Q37: