SQL: GATE CS Previous Year Questions

SQL · Databases

43 questions · asked in 23 of 27 years (2000–2026)

MCQ 34 · MSQ 1 · NAT 81-mark 26 · 2-mark 17

2000Questions per year2026

Questions 31–35 of 43

Q31GATE 20051 markMCQ−0.33 if wrong
In an inventory management system implemented at a trading corporation, there are several tables designed to hold all the information. Amongst these, the following two tables hold information on which items are supplied by which suppliers, and which warehouse keeps which items along with the stock-level of these items.
Supply = (supplierid, itemcode)
Inventory = (itemcode, warehouse, stocklevel)
For a specific information required by the management, following SQL query has been written
 Select distinct STMP.supplierid 
From Supply as STMP
Where not unique (Select ITMP.supplierid
                            From Inventory, Supply as ITMP
                            Where STMP.supplierid = ITMP.supplierid
                            And ITMP.itemcode = Inventory.itemcode
                            And Inventory.warehouse = 'Nagpur');

For the warehouse at Nagpur, this query will find all suppliers wh

Q32GATE 20051 markMCQ−0.33 if wrong
A table 'student' with schema (roll, name, hostel, marks), and another table 'hobby' with schema (roll, hobbyname) contains records as shown below:
RollNameHostelMarks1798Manoj Rathor7952154Soumic Banerjee5682369Gumma Reddy7862581Pradeep pendse6922643Suhas Kulkarni5782711Nitin Kadam8722872Kiran Vora5922926Manoj Kunkalikar5942959Hemant Karkhanis7883125Rajesh Doshi582Table: student\overset{\text{Table: student}}{\begin{array}{|c|c|c|c|} \hline \textbf{Roll} & \textbf {Name} & \textbf {Hostel} & \textbf{Marks} \\\hline \text{1798} & \text{Manoj Rathor} & \text{7} & \text{95} \\\hline \text{2154} & \text{Soumic Banerjee} & \text{5} & \text{68}\\\hline \text{2369} & \text{Gumma Reddy} & \text{7} & \text{86}\\\hline\text{2581} & \text{Pradeep pendse} & \text{6} & \text{92}\\\hline \text{2643} & \text{Suhas Kulkarni} & \text{5} & \text{78} \\\hline \text{2711} & \text{Nitin Kadam} & \text{8} & \text{72}\\\hline \text{2872}& \text{Kiran Vora} & \text{5} & \text{92}\\\hline\text{2926} & \text{Manoj Kunkalikar} & \text{5} & \text{94}\\\hline \text{2959}& \text{Hemant Karkhanis} & \text{7} & \text{88}\\\hline\text{3125} & \text{Rajesh Doshi} & \text{5} & \text{82}\\\hline \end{array}}

Table: hobbyRollHobby Name1798chess1798music2154music2369swimming2581cricket2643chess2643hockey2711volleyball2872football2926cricket2959photography3125music3125chess\overset{\text{Table: hobby}}{}\\\begin{array}{|c|c|} \hline \textbf{Roll} & \textbf {Hobby Name} \\\hline \text{1798} & \text{chess} \\\hline \text{1798} & \text{music} \\\hline \text{2154} & \text{music} \\\hline \text{2369} & \text{swimming}\\\hline \text{2581} & \text{cricket} \\\hline \text{2643} & \text{chess}\\\hline\text{2643} & \text{hockey} \\\hline \text{2711} & \text{volleyball}\\\hline \text{2872} & \text{football} \\\hline \text{2926} & \text{cricket} \\\hline \text{2959} & \text{photography} \\\hline \text{3125} & \text{music}\\\hline \text{3125}& \text{chess}\\\hline \end{array}
The following SQL query is executed on the above tables:
 
select hostel
from student natural join hobby
where marks >= 75 and roll between 2000 and 3000;

Relations S and H with the same schema as those of these two tables respectively contain the same information as tuples. A new relation S is obtained by the following relational algebra operation:
S′=Πhostel((σs.roll=H.roll(σmarks>75 and roll>2000 and roll<3000(S))×(H))S' = \Pi_{\text{hostel}} ((\sigma_{s.roll = H.roll} (\sigma_{marks \gt 75\text{ and }roll \gt 2000\text{ and }roll \lt 3000} (S)) \times (H))
The difference between the number of rows output by the SQL statement and the number of tuples in S' is

Q33GATE 20051 markMCQ−0.33 if wrong
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?
 select title
  from book as B
  where (select count(*)
     from book as T
     where T.price > B.price) < 5 

Q34GATE 20041 markMCQ−0.33 if wrong
Consider two tables in a relational database with columns and rows as follows:

Roll_noNameDept_id1ABC12DEF13GHI24JKL3Table: StudentDept_idDept_name1A2B3CTable: Department\overset{\text{Table: Student}}{\begin{array}{|c|c|c|} \hline \textbf {Roll\_no} & \textbf{Name} & \textbf{Dept\_id} \\\hline 1& \text{ABC} & 1\\\hline 2& \text{DEF} & 1 \\\hline 3 & \text{GHI} & 2\\\hline 4 & \text{JKL} & 3\\\hline \end{array}} \qquad \overset{\text{Table: Department}}{\begin{array}{|c|c|c|} \hline \textbf {Dept\_id} & \textbf{Dept\_name} \\\hline 1& \text{A} \\\hline 2& \text{B} \\\hline 3 & \text{C} \\\hline \end{array}}

Roll_no is the primary key of the Student table, Dept_id is the primary key of the Department table and Student.Dept_id is a foreign key from Department.Dept_id

What will happen if we try to execute the following two SQL statements?
update Student set Dept_id = Null where Roll_on = 1
update Department set Dept_id = Null where Dept_id = 1

Q35GATE 20041 markMCQ−0.33 if wrong
A table T1 in a relational database has the following rows and columns:

Roll no. Marks1102203304NULL\begin{array}{|c|c|c|} \hline \text {Roll no. } & \text {Marks} \\\hline 1& 10 \\\hline 2 & 20 \\\hline3 & 30 \\\hline 4 & \text{NULL}\\\hline \end{array}

The following sequence of SQL statements was successfully executed on table T1.
 Update T1 set marks = marks + 5
Select avg(marks) from T1
What is the output of the select statement?

Keep practising

Topics in Databases

All CS topics ›