Computer Knowledge

Database and SQL

3,929 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. The instance of the Command object can either be to create or optional.

  2. Write method is executed to provide the query specific results in the database.

  3. DataReader provides a series of methods that allow access to column values in their native data types.

  4. The DataReader cannot maintain the execution flow at each level at one stage.

  5. It manages the execution only at one level.

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

This is correct as the underlying data type is known, reducing the amount of type conversion required when retrieving the column value.

Multiple choice
  1. It specifies that the streaming objects are now closed after the operation is performed by the client.

  2. It shows that an error occurred in a Stream, XmlReader or TextReader object during a streaming operation.

  3. It specifies that current state of the connection is closed. ExecuteReader requires an open SqlConnection.

  4. It shows that a SqlDbType other than Binary or VarBinary was used when Value was set to Stream.

  5. It shows the limited memory capacity in the application.

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

This is correct as the Stream, XmlReader or TextReader object was closed during a streaming operation.

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

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.