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. 5

  2. 6

  3. 7

  4. 8

  5. None of these

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

MS Access has 5 main summary (aggregate) operators available in the Totals row: Sum, Avg, Count, Min, and Max. Additional operators like StDev, Var, First, and Last exist but the 5 listed are the primary summary functions.

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. 1, 0

  2. 1, 2

  3. 1, 3

  4. 1, 5

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

The sub-query places an equity join between 2 tables and select age > 65. So, pids 1, 2 and 3 are selected. In the main query, from 1, 2 and 3, only 1 and 3 have class AC.  

Multiple choice
  1. BankAccount_Number is a candidate key

  2. Registration_Number can be a primary key

  3. UID is a candidate key if all students are from the same country

  4. If S is a superkey such that S UID $\cap$ is NULL then S $\cup$ UID is also a superkey
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In case two students hold joint account then BankAccount_Num will not uniquely determine other attributes.

Multiple choice
  1. Ordered indexing will always outperform hashing for both queries.

  2. Hashing will always outperform ordered indexing for both queries.

  3. Hashing will outperform ordered indexing on Q1, but not on Q2.

  4. Hashing will outperform ordered indexing on Q2, but not on Q1.

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

Q1 uses equality (A_p = c) - hash indexing is optimal for exact match queries (O(1) average case). Q2 uses range query (c1 ≤ A_p ≤ c2) - ordered indexing (B+ tree) is better for range queries as it can efficiently traverse adjacent entries. Hash indexing cannot support range queries efficiently. Therefore, hashing outperforms on Q1 but not on Q2.

Multiple choice
  1. 3

  2. 9

  3. 5

  4. 6

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

After executing the given query, the output would be

Multiple choice
  1. 127

  2. 255

  3. 129

  4. 257

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

||| |---|---| | X| Y| | 1| 1| | 2| 3| | 3| 7| | 4| 15| | 5| 31| | 6| 63| | 7| 127|  

Multiple choice
  1. An attribute of an entity can have more than one value.

  2. An attribute of an entity can be composite.

  3. In a row of a relational table, an attribute can have more than one value.

  4. In a row of a relational table, an attribute can have exactly one value or a NULL value.

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

In a row of a relational table, an attribute cannot have more than one value.

Multiple choice
  1. P and R

  2. P and S

  3. Q and R

  4. Q and S

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

We use a HAVING clause without a GROUP BY clause, the HAVING condition applies to all rows that satisfy the search condition. In other words, all rows that satisfy the search condition make up a single group. So, option P is true and Q is false. Function of GROUP BY clause is to group the result obtained using one or more attributes. If attribute name is not present in SELECT clause then GROUP BY cannot find the attribute name in the result according to which result is supposed to be grouped. So, option R is true and S is false.

Multiple choice
  1. $\prod_{B}(r_{1})- \prod_{C}(r_{2})= \varnothing$
  2. $\prod_{C}(r_{2})- \prod_{B}(r_{1})= \varnothing$
  3. $\prod_{B}(r_{1}) = \prod_{C}(r_{2})$
  4. $\prod_{B}(r_{1}) - \prod_{C}(r_{2}) \neq \varnothing$
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Since B is a foreign key referring C, $ \prod_{B}(r_{1}) \subseteq \prod_{C}(r_{2} \Rightarrow \prod_{B}(r_{1})- \prod_{C}(r_{2})= \varnothing$

Multiple choice
  1. I, II, III and IV

  2. I, II and III only

  3. I, II and IV only

  4. II, III and IV only

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

Four queries given in SQL, RA, TRC and DRC in four statements respectively retrieve the required information.

Multiple choice
  1. $\Pi_{a_1, a_2, … a_n} \sigma_p \left(r_1 \times r_2 \times \dots \times r_m\right)$
  2. $\Pi_{a_1, a_2, … a_n} \sigma_p \left(r_1 \bowtie r_2 \bowtie \dots \bowtie r_m \right)$
  3. $\Pi_{a_1, a_2, … a_n} \sigma_p \left(r_1 \cup r_2 \cup \dots \cup r_m \right)$
  4. $\Pi_{a_1, a_2, … a_n} \sigma_p \left(r_1 \cap r_2 \cap \dots \cap r_m \right)$
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation