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. At the end of the run

  2. Beginning of next run

  3. At any point of Time

  4. Can't be done

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

Working tables should be truncated at the beginning of the next run, not at the end of the current run. This allows verification that the previous run completed successfully before clearing data. Truncating at the end risks losing the working data if an error occurs before verification. The beginning of the next run ensures a clean slate while preserving the previous run's data for audit purposes.

Multiple choice technology databases
  1. remove

  2. comment the code

  3. Either of them should be fine

  4. Don't do anything

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

Commenting out code preserves it for reference while preventing execution, which is the standard practice for script maintenance. Deleting code permanently loses the logic, which cannot be recovered if needed later. This approach allows rollback without version control.

Multiple choice technology databases
  1. explicit reference to partitions

  2. use the partition key in filter condition

  3. query will automatically decide the partition

  4. All of the above

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

Using the partition key in filter conditions enables partition pruning, where the optimizer automatically accesses only relevant partitions. Explicit partition references make code rigid and break when partitions change. The query optimizer automatically selects partitions based on the partition key in WHERE clauses.

Multiple choice technology databases
  1. True

  2. False

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

You don't necessarily need to check if a table exists before creating it. You can use CREATE TABLE IF NOT EXISTS syntax, or let the database return an error if it exists. While checking is good practice in some contexts, it's not mandatory. The statement incorrectly presents it as a requirement.

Multiple choice technology
  1. No history is maintained

  2. The key gets updated with the changed attributes

  3. History maintained

  4. new or prior attribute values

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

Slowly Changing Dimension Type 2 maintains complete historical data by adding a new row for each change rather than updating existing records. Each version includes effective date and expiry date columns (or current record flag) to track when the attribute value was valid, enabling full historical analysis and trend identification.

Multiple choice technology mainframe
  1. FETCH 10 ROWS ONLY

  2. GET FIRST 10 ROWS

  3. SELECT FIRST 10 ROWS

  4. FETCH FIRST 10 ROWS ONLY

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

DB2 uses the syntax 'FETCH FIRST 10 ROWS ONLY' to limit query results. This must be placed at the end of the SELECT statement after the ORDER BY clause if sorting is needed. Options A, B, and C use incorrect keywords or word order that don't match DB2 SQL syntax.

Multiple choice technology mainframe
  1. SORT IN

  2. SORT BY

  3. ORDER BY

  4. ORDER

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

DB2 uses 'ORDER BY' for sorting query results, not SORT BY or SORT. This is standard SQL syntax used across most relational databases. The ORDER BY clause comes after the FROM and WHERE clauses and before FETCH FIRST.

Multiple choice technology mainframe
  1. Search

  2. Search All

  3. In-Line Perform

  4. All the above

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

With fewer than 20 elements, an In-Line Perform is more efficient than Search or Search All. In-Line PERFORM eliminates the overhead of setup and search algorithm calls for tiny datasets. Search and Search All add overhead for table scanning and index management that only pays off with larger datasets. 'All the above' is incorrect since they're not equally preferred.

Multiple choice technology mainframe
  1. Use SELECT UNION(*)...in db2 query

  2. Use SELECT DISTINCT...in db2 query

  3. Use SELECT UNION ALL(...)...in db2 query

  4. Use SELECT DISTINCT ALL(*)...in db2 query

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

SELECT DISTINCT eliminates duplicate rows from DB2 query results by returning only unique rows. DISTINCT is the standard SQL keyword for removing duplicates. UNION combines results from multiple queries (removing duplicates), UNION ALL keeps all rows including duplicates, and DISTINCT ALL(*) is not valid SQL syntax.

Multiple choice technology mainframe
  1. Only Active Cards

  2. Active and Inactive Cards

  3. Cancelled Cards

  4. Expired Cards

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

The CARD_PERS_ENHANCED table in CMHDB stores only active cards, excluding inactive, cancelled, or expired cards. This design separates current valid cards from historical or invalid card records for performance and clarity.

Multiple choice technology mainframe
  1. INSERT NBR = (Hopper Number -1) * 10.

  2. INSERT NBR = Hopper Number * 10.

  3. INSERT NBR = (Hopper Number + 1) * 10.

  4. INSERT NBR = Hopper Number

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

In statement printing and insert machinery control, insert numbers map to physical hoppers. The formula maps Hopper 1 to Insert Number 0, Hopper 2 to 10, and Hopper 3 to 20. This relationship is mathematically expressed as (Hopper Number - 1) * 10, making the other linear options incorrect.

Multiple choice technology mainframe
  1. Account cancelled for collection

  2. Account being cancelled for inactivity

  3. Account cancelled and transferred to another account number

  4. Card cancelled due to death

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

In legacy card management systems, the RM database tracks specific card and account status codes. Status code 02 indicates that an account is pending cancellation or is being cancelled specifically due to inactivity. Other codes represent cancellation due to cardholder death, collection procedures, or account number transfers.

Multiple choice technology mainframe
  1. Because, Occurs is used to repeat records.

  2. Occurs is used to repeat fields with same format and not the records.

  3. Only occurs with INDEX can be used in 01 level.

  4. None of the above.

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

In COBOL, the OCCURS clause is used to define repeating fields (array elements) within a record, not repeating records themselves. The 01 level defines the record structure itself, so OCCURS cannot be applied there - it's used at subordinate levels (02-49) to repeat fields with the same format. Option A is incorrect because OCCURS doesn't repeat entire records.