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 technology databases
  1. Structured Query Language

  2. Strong Question Language

  3. Structured Question Language

  4. None

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

SQL stands for Structured Query Language, the standard language for relational database management systems. It's used for querying, updating, and managing data. Options B and C incorrectly substitute 'Question' for 'Query'.

Multiple choice technology databases
  1. SELECT Persons.FirstName

  2. SELECT FirstName FROM Persons

  3. EXTRACT FirstName FROM Persons

  4. None

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

To select a specific column from a table, use SELECT column_name FROM table_name. This retrieves only the specified column for all rows. Option A uses incorrect dot notation (Persons.FirstName), C uses non-existent EXTRACT keyword, and the syntax for column selection is simply SELECT followed by the column name.

Multiple choice technology programming languages
  1. SELECT (A); WHEN (A=0) PUT LIST(‘A = 0‘); WHEN (A=5) PUT LIST (‘A = 5‘); OTHERWISE PUT LIST (‘A IS NOT 0 NOR 5’); END;

  2. SELECT (A); WHEN (0) PUT LIST(‘A = 0‘); WHEN (5) PUT LIST (‘A = 5‘); OTHERWISE PUT LIST (‘A IS NOT 0 NOR 5’); END;

  3. SELECT; WHEN (A=0) PUT LIST(‘A = 0‘); WHEN (5) PUT LIST (‘A = 5‘); OTHERWISE PUT LIST (‘A IS NOT 0 NOR 5’); END;

  4. All of the above

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

Option B is correct because PL/I SELECT statements allow WHEN clauses with simple expressions that evaluate against the selector value. Option A is wrong because WHEN (A=0) is a comparison, not the value itself. Option C is wrong because it omits the selector (A) after SELECT. Option D is wrong since only B is correct.

Multiple choice technology mainframe
  1. For Renames Clause

  2. For Condition Names

  3. Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor can they be subdivided themselves.

  4. All of the above

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

In COBOL, level number 66 is specifically reserved for the RENAMES clause, which allows regrouping or renaming previously defined elementary items. Level 88 is used for condition names, and level 77 is used for independent elementary items.

Multiple choice technology databases
  1. True

  2. False

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

Primary Key constraints cannot contain NULL values by definition. Each row must have a unique, non-NULL identifier. This is a fundamental property of primary keys in relational databases.

Multiple choice technology databases
  1. True

  2. False

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

A composite key combines multiple columns to create a unique identifier. The entire combination cannot be NULL, though individual components might allow NULLs in some systems. For the key to function as an identifier, at least one component must be non-NULL.

Multiple choice technology databases
  1. MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen'

  2. MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen

  3. UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'

  4. UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'

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

The UPDATE statement modifies existing data in a table. The correct syntax is UPDATE table_name SET column=new_value WHERE condition. Option D correctly changes 'Hansen' to 'Nilsen' for all matching rows. MODIFY is not a valid SQL keyword.

Multiple choice technology databases
  1. SELECT COUNT(*) FROM Persons

  2. SELECT COLUMNS(*) FROM Persons

  3. SELECT COLUMNS() FROM Persons

  4. SELECT COUNT() FROM Persons

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

COUNT() is an aggregate function that returns the total number of rows in a table. The asterisk () indicates count all rows regardless of NULL values. Options B, C, and D use incorrect syntax (COLUMNS is not a valid SQL keyword, and COUNT() requires the * parameter).

Multiple choice technology databases
  1. SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter'

  2. SELECT * FROM Persons WHERE FirstName<>'Peter'

  3. SELECT [all] FROM Persons WHERE FirstName='Peter'

  4. SELECT * FROM Persons WHERE FirstName='Peter'

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

SELECT * retrieves all columns, and WHERE FirstName='Peter' filters for exact matches. The = operator is for exact matching (not LIKE, which is for patterns). Options A and C incorrectly use [all] instead of *, and option B uses <> (not equal) which would exclude 'Peter'.

Multiple choice technology databases
  1. SELECT * FROM Persons WHERE FirstName LIKE '%a'

  2. SELECT * FROM Persons WHERE FirstName='%a%'

  3. SELECT * FROM Persons WHERE FirstName='a'

  4. SELECT * FROM Persons WHERE FirstName LIKE 'a%'

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

The LIKE operator with 'a%' matches any string starting with 'a' followed by any characters. The % is a wildcard representing zero or more characters. Option A's '%a' matches ending with 'a', B's syntax is invalid, C matches only exact 'a', and D's 'a%' correctly matches starting with 'a'.

Multiple choice technology databases
  1. SELECT * FROM Persons SORT BY 'FirstName' DESC

  2. SELECT * FROM Persons SORT 'FirstName' DESC

  3. SELECT * FROM Persons ORDER BY FirstName DESC

  4. SELECT * FROM Persons ORDER FirstName DESC

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

ORDER BY is the correct clause for sorting (not SORT BY), DESC specifies descending order, and column names don't require quotes. Option C has the correct syntax. Options A, B use invalid SORT keywords, and D is missing the BY.