GATE || DBMS || SQL & Relational Algebra || Pyq ( 2010 to 2025 )

Last Updated :
Discuss
Comments

Question 1

The relation scheme given below is used to store information about the employees of a company, where empId is the key and deptId indicates the department to which the employee is assigned. Each employee is assigned to exactly one department. 

emp (EMPID, name, gender, salary, deptId)

Consider the following SQL query:

select deptId, count(*)

from emp

where gender = “female” and salary > (select avg(salary) from emp)

group by deptId;

The above query gives, for each department in the company, the number of female employees whose salary is greater than the average salary of:

[GATE 2021 || SET- 2 MCQ || 2-mark]

  • employees in the company

  • female employees in the department.

  • employees in the department.

  • female employees in the company.

Question 2

SELECT operation in SQL is equivalent to
[GATE 2015 || SET-1 MCQ || 1-mark]

  • the selection operation in relational algebra

  • the selection operation in relational algebra, except that SELECT in SQL retains duplicates

  • the projection operation in relational algebra

  • the projection operation in relational algebra, except that SELECT in SQL retains duplicates

Question 3

Consider the following relations:

            Student

Roll_No

Student_Name

1

Raj

2

Rohit

3

Raj


                 Performances

Roll_No

Course

Marks

1

Math

80

1

English

70

2

Math

75

3

English

80

2

Physics

65

3

Math

80

SELECT S. student_Name, sum(P.Marks) 

FROM Student S, Performance P 

WHERE S.Roll_No = P.Roll_no

GROUP BY S.Student_Name

The number of rows that will be returned by the SQL query is _______?
[GATE 2015|| SET-1 NAT || 2-mark]

  • 2

Question 4

Consider the following database table named water_schemes:

water-schemes

scheme_no

district_name

Capacity

1

1

2

3

1

2

1

Ajmer

Bikaner

Bikaner

Bikaner

Churu

Churu

Dungargarh

20

10

10

20

10

20

10

The number of tuples returned by the following SQL query is _______.

with total(name, capacity) as	
    select district_name, sum(capacity)
	from water_schemes	
group by district_name	
with total_avg(capacity) as	
select avg(capacity)	
from total 	
select name	
from total, total_avg	
where total.capacity>total_avg.capacity;     [GATE 2016|| SET-2 NAT || 2-mark]


  • 2

Question 5

Consider a database that has the relation schema EMP (EmpId, EmpName, and DeptName). An instance of the schema EMP and a SQL query on it are given below.

EMP

Empld

Emp Name

DeptName

1

XYA

AA

2

XYB

AA

3

XYC

AA

4

XYD

AA

5

XYE

AB

6

XYF

AB

7

XYG

AB

8

XYH

AC

9

XYI

AC

10

XYJ

AC

11

XYK

AD

12

XYL

AD

13

XYM

AE


SELECT AVG (EC.Num)

FROM EC

WHERE (DeptName, Num) IN

(SELECT DeptName, COUNT(EmpId) AS EC(DeptName, Num)

FROM EMP

GROUP BY DeptName);

The output of executing the SQL query is ______? [GATE 2017|| SET-1 NAT || 1-mark ]


  • 2.6

Question 6

Consider a database that has the relation schemas EMP(Empld, EmpName, Deptld) and DEPT(DeptName, Deptld). Note that the Deptld can  be permitted to a NULL in the relation EMP. Consider the following queries on the database expressed in tuple relational calculus.

(I) {t|∃u ϵ EMP(t[EmpName) = u[EmpName] Λ ∀ ϵ DEPT(t[Deptld] ≠ V[Deptld]))}

(II) {t|∃u ϵ EMP(t[EmpName) = u[EmpName] Λ ∃∨ ϵ DEPT(t[Deptld] ≠V[Deptld]))}

(III) {t|∃u ϵ EMP(t[EmpNmae) = u[EmpName] Λ ∃∨ ϵ DEPT(t[Deptld] =V[Deptld]))}

Which of the above queries are safe? [GATE 2017|| SET-1 MCQ || 1-mark ]

  •  I and II only

  • I and III only

  • II and III only

  • I, II and III.

Question 7

Consider the following two tables and four queries in SQL .

Book (isbn, bname), Stock (isbn, copies)

Query 1:      SELECT B.isbn, S.copies

FROM BOOK B INNER JOIN Stock S

ON B.isbn = S.isbn; 

Query 2:      SELECT B.isbn, S.copies

FROM BOOK B LEFT OUTER JOIN Stock S 

ON B.isbn=S.isbn;

Query 3:      SELECT B.isbn, S.copies

FROM BOOk B RIGHT OUTER JOIN Stock S 

ON B.isbn = S.isbn;

Query 4:   SELECT B.isbn, S.copies

FROM BOOk B FULL OUTER JOIN Stock S

ON B.isbn = S.isbn;

Which one of the queries above is certain to have an output that is a superset of the outputs of the other three queries? [GATE 2018 MCQ || 1-mark]

  • Query 1

  • Query 2

  • Query 3

  • Query 4

Question 8

Consider the following relations P(X, Y, Z), Q(X, Y, T) and R(Y, V).  [GATE 2019 || NAT || 2-mark]


Table : P

XYZ
X1Y1Z1
X1Y1Z1
X2Y2Z2
X2Y4Z4

Table : Q

XYT
X2Y12
X1Y25
X1Y16
X3Y31

Table : R

YV
Y1V1
Y3V2
Y2V3
Y2V2

How many tuples will be returned by the following relational algebra query?

πx(σ(P.Y = R.Y ∧ R.V = V(P X R))) - πx(σ(Q.Y = R.Y ∧ Q.T > 2(Q X R))) 
  • 1

Question 9

A relational database contains two tables Student and Performance as shown below

Student

Roll_no.

Student_name

1

Amit

2

Priya

3

Vinit

4

Rohan

5

Smita


Performance

Roll_no.

Student_name

Marks

1

A

86

1

B

95

1

C

90

2

A

89

2

C

92

3

C

80

The primary key of the Student table is Roll_no. For the Performance table, the columns Roll_no. and Subject_code together from the primary Key. Consider the SQL query given below.

SELECT S.Student.name, sum (P.Marks) 

FROM Student S, Performance P 

WHERE P.Marks> 84

GROUP BY S.Student_name;

The number of rows returned by the above SQL query is _________? [GATE 2019 || NAT || 2-mark]


  • 5

Question 10

Consider a relational database containing the following schemas.

Catalogue

sno

Pno

cost

S1

P1

150

S1

P2

50

S1

P3

100

S2

P4

200

S2

P5

250

S3

P1

250

S3

P2

150

S3

P5

300

S3

P4

250


Suppliers 

sno

Sname

location

S1

M/s Royal furniture

Delhi

S2

M/s Balaji furniture

Bangalore

S3

M/s Premium furniture

Chennai


Parts

pno

Sname

Location

P1

Table

Wood

P2

Chair

Wood

P3

Table

Steel

P4

Almirah

Steel

P5

Almirah

Wood


The primary key of each table is indicated by underlying the constituent fields.

SELECT s.sno, s.sname

FROM Suppliers s, Catalogue c 

WHERE s.sno = c.sno AND

Cost > (SELECT AVG (cost) 

FROM Catalogue 

WHERE pno = 'P4' 

GROUP BY pno);

The number of rows returned by the above SQL query is __________. [GATE 2020 || NAT || 2-mark]

  • 4

Tags:

There are 37 questions to complete.

Take a part in the ongoing discussion