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 databases
  1. COL1

  2. COL2

  3. COL3

  4. COL4

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

COL2 is the definition that will cause failure because VARCHAR columns cannot have DEFAULT NONE in DB2. The DEFAULT clause for VARCHAR must specify a valid string value or be omitted entirely. COL1, COL3, and COL4 definitions are syntactically valid.

Multiple choice technology databases
  1. Check constraint

  2. Default constraint

  3. Unique constraint

  4. Informational constraint

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

A UNIQUE constraint ensures a column will not accept NULL values (in most DBMS implementations) and creates an index that can be referenced by a foreign key. CHECK constraints only validate data values, DEFAULT constraints provide fallback values, and INFORMATIONAL is not a standard constraint type.

Multiple choice technology databases
  1. ADMIN Privileges

  2. CREATETAB Privileges

  3. No Privileges

  4. USERTAB Privileges

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

In DB2 and similar SQL databases, the specific privilege required to create a table is CREATETAB. General administrative privileges are not strictly necessary, and USERTAB is not a valid privilege.

Multiple choice technology databases
  1. It has to be in a CURSOR

  2. cannot be used in Embedded SQL

  3. No restrictions

  4. None of the above

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

UNION must be declared within a CURSOR in embedded SQL because embedded SQL requires declared cursors for result set processing. This is a restriction specific to embedded SQL environments where result sets must be explicitly defined.

Multiple choice technology databases
  1. SELECT COUNT *

  2. SELECT COUNT(*)

  3. SELECT COUNT[*]

  4. SELECT COUNT(ALL)

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

SELECT COUNT() is the correct SQL syntax for counting all rows in a table. Option A is missing parentheses, C uses incorrect brackets, and D is not valid syntax for counting all rows. COUNT() counts all rows including NULLs.

Multiple choice technology databases
  1. jump

  2. run

  3. walk

  4. sleep

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

The RUN command in SQL*Plus executes the SQL statements stored in the current buffer. It processes the SQL command and displays the output. The other options (jump, walk, sleep) are not valid SQL*Plus commands.

Multiple choice technology databases
  1. soundex

  2. lightex

  3. weightex

  4. lux

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

SOUNDEX is a SQL function that converts strings to their phonetic representation. It enables finding words that sound similar but have different spellings, which is useful for name matching. The other options (lightex, weightex, lux) are not standard SQL functions.

Multiple choice technology databases
  1. floor

  2. window

  3. door

  4. ground

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

FLOOR is a valid Oracle SQL function that returns the largest integer less than or equal to a given number. For example, FLOOR(5.7) returns 5. The other options (window, door, ground) are not standard SQL functions in Oracle.

Multiple choice technology databases
  1. True

  2. False

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

SQL's ORDER BY clause can use column aliases defined in the SELECT statement. The aliases are created when SELECT processes the columns, making them available to ORDER BY in the same query level. This makes queries more readable by allowing descriptive names instead of expressions or column positions.

Multiple choice technology databases
  1. True

  2. False

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

SQL's ORDER BY clause defaults to ascending (ASC) order when no sort direction is explicitly specified. This means numbers sort from lowest to highest, dates from earliest to latest, and text alphabetically. To reverse this behavior, you must explicitly specify the DESC keyword.

Multiple choice technology databases
  1. True

  2. False

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

In SQL, NULL values are treated as the lowest possible values in sorting operations. When using ORDER BY with DESC (descending), NULL values appear first at the top of the result set. This behavior is consistent across most major database systems, though some databases provide options to control NULL positioning in sort order.

Multiple choice technology databases
  1. any outer join

  2. left outer join

  3. cross join

  4. right outer join

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

A RIGHT OUTER JOIN returns all rows from the right table (B) and matching rows from the left table (A), with NULL for non-matching left-side rows. LEFT OUTER JOIN would return all from A, CROSS JOIN is a Cartesian product, and ANY OUTER JOIN isn't valid SQL syntax.

Multiple choice technology databases
  1. CASCADE

  2. CONSTANT

  3. CHECK

  4. NONUNIQUE

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

CHECK is a valid Oracle constraint that enforces domain integrity by limiting values to a Boolean condition. CASCADE is an action (not a constraint type), CONSTANT isn't an Oracle constraint, and NONUNIQUE isn't a valid constraint (though it describes an index type). Oracle supports PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, and CHECK constraints.