Computer Knowledge

Database and SQL

4,213 Questions

Master structured query language commands, database joins, table constraints, and alias generation. This section covers relational database management concepts and query outputs essential for technical aptitude. These technical questions feature prominently in banking IT officer exams and computer knowledge sections.

SQL queries and aliasesDatabase table constraintsDatabase joins and transformationsStored procedures and functions

Database and SQL Questions

Multiple choice
  1. Names of students who have got an A grade in all the courses taught by Korth.

  2. Names of students who have got an A grade in all the courses.

  3. Names of students who have got an A grade in at least one of the courses taught by Korth.

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Names are unique since they are selected distinct, so one person will be selected only once, even when he has got grade A in any number of courses taught by Korth. So, if a name is appearing it is not necessary that he scored grade A in all the courses, but scored grade A in at least one course.

Multiple choice
  1. 2 and 5

  2. 1 and 3

  3. 1 and 4

  4. 3 and 5

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Multiple choice
  1. in second normal form but not in third normal form

  2. in third normal form but not in BCNF

  3. in BCNF

  4. None of the above

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Multiple choice
  1. Q1 is the correct query.

  2. Q2 is the correct query.

  3. Both Q1 and Q2 produce the same answer.

  4. Neither Q1 nor Q2 is the correct query.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Multiple choice
  1. All queries return identical row sets for any database.

  2. Query2 and Query4 return identical row sets for all databases but there exist databases for which Query1 and Query2 return different row sets.

  3. There exist databases for which Query3 returns strictly fewer rows than Query 2.

  4. There exist databases for which Query4 will encounter an integrity violation at runtime.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Multiple choice
  1. Plan 1 and Plan 2 will not output identical row sets for all databases

  2. A course may be listed more than once in the output of Plan 1 for some databases

  3. For x = 5000, Plan 1 executes faster than Plan 2 for all databases

  4. For x = 9000, Plan I executes slower than Plan 2 for all databases.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Multiple choice
  1. Find the names of all suppliers who have supplied a non-blue part.

  2. Find the names of all suppliers who have not supplied a non-blue part.

  3. Find the names of all suppliers who have supplied only blue parts.

  4. Find the names of all suppliers who have not supplied only blue parts.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Multiple choice
  1. 8, 8

  2. 120, 8

  3. 960, 8

  4. 960, 120

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The boundary cases are when either all the tuples of Enroll table belong to one roll number, so there can be at most 8 roll number and course number combinations or the other case is when all the tuples belong to different roll no. this also has 8 tuples. So (8,8) = (max,min)

Multiple choice
  1. (3,4) and (6,4)

  2. (5,2) and (7,2)

  3. (5,2)(7,2) and (9,5)

  4. 1

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

On delete cascade says that deletion of a primary key value should delete its all foreign key references. So in (2,4) 2 is primary key so tuples (5,2) & (7,2) should be deleted, but in (5,2) 5 is also a key so (9,5) also deleted cascade.

Multiple choice
  1. A tuple (z,w) with z > y is deleted.

  2. A tuple (z,w) with z > x is deleted.

  3. A tuple (z,w) with w < x is deleted.

  4. The deletion of (x,y) is prohibited.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Multiple choice
  1. Titles of the four most expensive books

  2. Title of the fifth most inexpensive book

  3. Title of the fifth most expensive book

  4. Titles of the five most expensive books

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This SQL query selects the titles of the five most expensive books by comparing with each other.

Multiple choice
  1. Department address of every employee

  2. Employee whose name is the same as its department name

  3. The sum of all employee salaries

  4. All employees of a given department

Reveal answer Fill a bubble to check yourself
C Correct answer
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.

Multiple choice
  1. select distinct p.pname from parts P, SP a, SP b where a.Pno = b.Pno and a.Sid = b.sid and a.Pno = P.pno

  2. select distinct P.name from parts P, SP a, SP b where a.pno = b.pno and a.sid < > b.sid and P.Pno = a.Pno

  3. cannot be determined

  4. none of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

To find parts with more than one supplier, we need to identify parts supplied by at least two DIFFERENT suppliers. Option B correctly self-joins the SP table twice with alias a and b, requiring the same part number (a.pno = b.pno) but DIFFERENT supplier IDs (a.sid <> b.sid), then joins with Parts to get the name. Option A is incorrect because it requires a.Sid = b.sid, which would find the same supplier twice.

Multiple choice
  1. Gives error, since we are deleting the table.

  2. In student $\theta$ table we add new attributes as subject.
  3. In student table we have one tuple with values “Hitesh”, 1220,”B.tech”.

  4. In student table we have one tuple with value “Hitesh”, 1928. an “B.E”.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

First we insert values in student table as “Hitesh”, 1928, “B.E”. Then we delete tuple from student but table is still known to database, if it is an empty relation.After that we again inserting tuple into student having values “Hitesh”, 1220, and “B.Tech”After that by using ALTER command we add one attribute as subject.After that we again use ALTER command to drop attribute subject.So we remain with student relation having values “Hitesh”, 1220,'B.Tech”