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 36–40 of 43
A relational database contains two tables student and department in which student table has columns roll_no, name and dept_id and department table has columns dept_id and dept_name. The following insert statements were executed successfully to populate the empty tables:
Insert into department values (1, 'Mathematics')
Insert into department values (2, 'Physics')
Insert into student values (l, 'Navin', 1)
Insert into student values (2, 'Mukesh', 2)
Insert into student values (3, 'Gita', 1) How many rows and columns will be retrieved by the following SQL statement?
Select * from student, department
Answer: (D)
No joining condition is given. So the query returns the Cartesian product of the two tables.
Rows in the result = product of the row counts of the two tables:
Columns in the result = sum of the column counts of the two tables:
Answer: D.
Rows in the result = product of the row counts of the two tables:
Columns in the result = sum of the column counts of the two tables:
Answer: D.
The employee information in a company is stored in the relation
Employee (, sex, salary, deptName)
Consider the following SQL query
Employee (, sex, salary, deptName)
Consider the following SQL query
select deptName
from Employee
where sex = 'M'
group by deptName
having avg (salary) > (select avg (salary) from Employee) It returns the names of the department in whichAnswer: (D)
Follow the order in which the query is evaluated.
1. where sex = 'M' keeps only male employees, before any grouping.
2. group by deptName makes one group per department of these male employees, so avg(salary) in having is the average salary of the male employees in that department.
3. The inner query select avg(salary) from Employee has no condition, so it is the average salary of all employees in the company, male and female.
So the query returns the departments where the average salary of male employees is more than the average salary in the company.
(A) is wrong because the department average counts males only. (B) is wrong because the inner query averages all employees, not only males. (C) is wrong because the comparison is with the whole company, not with the same department.
Answer: (D)
1. where sex = 'M' keeps only male employees, before any grouping.
2. group by deptName makes one group per department of these male employees, so avg(salary) in having is the average salary of the male employees in that department.
3. The inner query select avg(salary) from Employee has no condition, so it is the average salary of all employees in the company, male and female.
So the query returns the departments where the average salary of male employees is more than the average salary in the company.
(A) is wrong because the department average counts males only. (B) is wrong because the inner query averages all employees, not only males. (C) is wrong because the comparison is with the whole company, not with the same department.
Answer: (D)
Consider the following relation schema pertaining to a students database:
Students (, name, address)
Enroll ( ,, coursename)
Where the primary keys are shown underlined. The number of tuples in the student and Enroll tables are 120 and 8 respectively. What are the maximum and minimum number of tuples that can be present in (Student * Enroll), where '*' denotes natural join?
Students (, name, address)
Enroll ( ,, coursename)
Where the primary keys are shown underlined. The number of tuples in the student and Enroll tables are 120 and 8 respectively. What are the maximum and minimum number of tuples that can be present in (Student * Enroll), where '*' denotes natural join?
Answer: (A)
In Students, rollno is the key, so each roll number appears at most once. The natural join matches tuples on the common attribute rollno. It is the only common attribute, because name, address and coursename are different names.
Maximum: each Enroll tuple matches at most one Students tuple, because rollno is unique in Students. So the result has at most 8 tuples.
Minimum: rollno in Enroll is taken as a foreign key that refers to Students, so every Enroll tuple finds exactly one matching student. So the result has at least 8 tuples.
Both counts are 8. 120 is not possible, because every result tuple comes from one Enroll tuple. 960 is , the size of a cross product, not a join on the key.
Answer: (A)
Maximum: each Enroll tuple matches at most one Students tuple, because rollno is unique in Students. So the result has at most 8 tuples.
Minimum: rollno in Enroll is taken as a foreign key that refers to Students, so every Enroll tuple finds exactly one matching student. So the result has at least 8 tuples.
Both counts are 8. 120 is not possible, because every result tuple comes from one Enroll tuple. 960 is , the size of a cross product, not a join on the key.
Answer: (A)
Consider the set of relations shown below and the SQL query that follow:
Students:(Roll_number,Name,Date_of_birth)
Courses:(Course_number,Course_name,Instructor)
Grades:(Roll_number,Course_number,Grade) select distrinct Name
from Students, Courses, Grades
Where Students.Roll_number=Grades.Toll_number
and Courses.Instructor= 'Korth'
and Courses.Course_number=Grades.Course_number
and Grades.grade= 'A' Which of the following sets is computed by the above query?Answer: (C)
The query joins Students, Courses and Grades, and keeps a row only when the course is taught by Korth, the grade in that row is 'A', and the student matches the grade. (The words "distrinct" and "Toll_number" are typing slips for distinct and Roll_number.)
One such row is enough to put the student's Name in the output, and distinct removes repeated names. So the output is the names of students who got an A in at least one course taught by Korth.
"All courses taught by Korth" (A) would need a division, or a not exists check that no Korth course is missing an A. This query has no such check. (B) is wrong because the query tests only Korth's courses, not all courses. (D) is wrong because (C) is correct.
Answer: (C)
One such row is enough to put the student's Name in the output, and distinct removes repeated names. So the output is the names of students who got an A in at least one course taught by Korth.
"All courses taught by Korth" (A) would need a division, or a not exists check that no Korth course is missing an A. This query has no such check. (B) is wrong because the query tests only Korth's courses, not all courses. (D) is wrong because (C) is correct.
Answer: (C)
Consider the following SQL query
select distinct
from
where P
For an arbitrary predicate P, this query is equivalent to which of the following relational algebra expressions?
A.
B.
C.
D.
select distinct
from
where P
For an arbitrary predicate P, this query is equivalent to which of the following relational algebra expressions?
A.
B.
C.
D.
Answer: (A)
Translate each clause of the query:
- from lists several relations, which is a cross product: .
- where P is the selection on that product.
- select distinct is the projection , which also removes duplicate tuples.
So the query is , which is expression A.
B is wrong because a natural join keeps only tuples that agree on common attributes, and the from list does not ask for that. C and D are wrong because union and intersection need relations with the same attributes and do not combine the attributes of different relations.
Answer: (A)
- from lists several relations, which is a cross product: .
- where P is the selection on that product.
- select distinct is the projection , which also removes duplicate tuples.
So the query is , which is expression A.
B is wrong because a natural join keeps only tuples that agree on common attributes, and the from list does not ask for that. C and D are wrong because union and intersection need relations with the same attributes and do not combine the attributes of different relations.
Answer: (A)
Keep practising