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 technology programming languages
  1. True

  2. False

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

In Oracle, tables can have a large but finite number of indexes - up to the limit on the number of segments per table, which is determined by the database configuration. While the limit is high (unlimited in practical scenarios), technically it's not unlimited. The question uses 'unlimited' in a practical sense.

Multiple choice technology databases
  1. Column

  2. 1966_Invoices

  3. Catch_#22

  4. #Invoices

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

Catch_#22 is valid because SQL identifiers can contain letters, numbers, underscores, and certain special characters like hash when properly quoted. Column is a reserved word in some databases, 1966_Invoices starts with a number (problematic in some SQL dialects), and #Invoices starts with a special character.

Multiple choice technology databases
  1. Drop

  2. Delete

  3. Cascade

  4. Truncate

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

TRUNCATE is a DDL command that quickly removes all rows by resetting the table without logging individual row deletions to the rollback segment. DELETE is DML that logs each deletion, DROP removes the entire table structure, and CASCADE is a constraint option for related deletions.

Multiple choice technology databases
  1. Primary key access

  2. Access via unique index

  3. Table access by ROWID

  4. Full table scan

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

ROWID is the physical disk address of a row, so accessing by ROWID is the fastest method - Oracle goes directly to the exact location. Primary key and unique index require traversing an index structure first, and full table scan reads every row in the table.

Multiple choice technology databases
  1. SQL cannot support object-orientation

  2. The same query can be written in many ways, each with vastly different execution plans.

  3. SQL syntax is too difficult for non-computer professionals to use

  4. SQL creates excessive locks within the database

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

A major problem with SQL is that logically equivalent queries can be written in multiple ways, and each variation may produce vastly different execution plans. This makes query optimization challenging - a simple syntax change can dramatically affect performance.

Multiple choice technology databases
  1. *

  2. /

  3. -

  4. =

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

In SQL*Plus, the hyphen (-) character is used to continue a SQL statement on the next line when a statement is too long. The asterisk (*) is a wildcard for SELECT, the forward slash (/) executes the current buffer, and equals (=) is used for substitution variables, not statement continuation.

Multiple choice technology databases
  1. select * from EMP where nvl(EMPNO, '00000') = '59384';

  2. select * from EMP where EMPNO = '59384';

  3. select EMPNO, LASTNAME from EMP where EMPNO = '59384';

  4. select 1 from EMP where EMPNO = '59834';

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

To solve this question, the user needs to understand the concept of indexes and how they work. An index is a data structure that improves the speed of data retrieval operations on a database table. It is created on one or more columns of a table to allow faster search and retrieval of data based on the values stored in those columns.

Now, let's go through each option and determine whether or not it will use the associated index on EMPNO:

A. select * from EMP where nvl(EMPNO, '00000') = '59384';

This option will not use the associated index on EMPNO. The nvl function in the where clause of this query will cause a full table scan to be performed instead of using the index. This is because the function modifies the column value, making it impossible to use the index for a direct lookup.

B. select * from EMP where EMPNO = '59384';

This option will use the associated index on EMPNO. The query filters on the exact value of EMPNO, which makes it possible to use the index for a direct lookup.

C. select EMPNO, LASTNAME from EMP where EMPNO = '59384';

This option will use the associated index on EMPNO. The query filters on the exact value of EMPNO and only selects the EMPNO and LASTNAME columns, making it possible to use the index for a direct lookup and avoid accessing the table rows.

D. select 1 from EMP where EMPNO = '59834';

This option will use the associated index on EMPNO. The query filters on the exact value of EMPNO, and although it does not retrieve any column values, the index can still be used to perform the lookup and avoid the full table scan.

Therefore, the option that will not use the associated index on EMPNO is:

A. select * from EMP where nvl(EMPNO, '00000') = '59384';

The Answer is: A

Multiple choice technology databases
  1. Indexes are only used in special cases

  2. Indexes are used to make table storage more efficient

  3. Indexes rarely make a difference in SQL performance

  4. Indexes exist solely to improve query speed.

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

Indexes exist specifically to accelerate data retrieval by providing optimized lookup paths. While indexes do consume storage (B), they are not for storage efficiency. They are widely used (contrary to A and C) and their primary purpose is query performance improvement.

Multiple choice technology databases
  1. 8

  2. 2

  3. 3

  4. 4

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

To avoid a cartesian product when joining N tables in a query, a minimum of N - 1 join conditions must be specified in the WHERE clause. Therefore, joining four tables requires at least three join conditions to properly relate all records without generating redundant combinations.

Multiple choice technology databases
  1. Indexes use B-TREE for searching data.

  2. Can create more than one non clustered index on a table.

  3. Up to 256 columns can be combined into a single composite index key.

  4. If not specified, a nonclustered index is created.

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

SQL Server indexes do use B-TREE structures (A is true), allow multiple nonclustered indexes per table (B is true), and create a nonclustered index by default when not specified (D is true). However, the limit for composite index columns is much lower than 256 - it's 16 columns (32 in some newer versions with limitations), making option C incorrect.