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
-
At the end of the run
-
Beginning of next run
-
At any point of Time
-
Can't be done
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.
-
remove
-
comment the code
-
Either of them should be fine
-
Don't do anything
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.
-
explicit reference to partitions
-
use the partition key in filter condition
-
query will automatically decide the partition
-
All of the above
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.
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.
B
Correct answer
Explanation
Comments explaining business logic are good practice but not required for SQL to execute. SQL is a declarative language that functions perfectly without comments. The statement incorrectly presents comments as mandatory.
A
Correct answer
Explanation
In COBOL and mainframe data entry, if the Name field (typically columns 1-3) is not used/coded, then the operand field can indeed start at column 4. This follows the fixed-format column positioning rules where unused fields can be skipped.
-
No history is maintained
-
The key gets updated with the changed attributes
-
History maintained
-
new or prior attribute values
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.
-
FETCH 10 ROWS ONLY
-
GET FIRST 10 ROWS
-
SELECT FIRST 10 ROWS
-
FETCH FIRST 10 ROWS ONLY
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.
-
SORT IN
-
SORT BY
-
ORDER BY
-
ORDER
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.
-
Search
-
Search All
-
In-Line Perform
-
All the above
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.
-
Use SELECT UNION(*)...in db2 query
-
Use SELECT DISTINCT...in db2 query
-
Use SELECT UNION ALL(...)...in db2 query
-
Use SELECT DISTINCT ALL(*)...in db2 query
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.
-
Only Active Cards
-
Active and Inactive Cards
-
Cancelled Cards
-
Expired Cards
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.
-
INSERT NBR = (Hopper Number -1) * 10.
-
INSERT NBR = Hopper Number * 10.
-
INSERT NBR = (Hopper Number + 1) * 10.
-
INSERT NBR = Hopper Number
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.
-
Account cancelled for collection
-
Account being cancelled for inactivity
-
Account cancelled and transferred to another account number
-
Card cancelled due to death
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.
-
Because, Occurs is used to repeat records.
-
Occurs is used to repeat fields with same format and not the records.
-
Only occurs with INDEX can be used in 01 level.
-
None of the above.
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.