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 mainframe
  1. A. A colon (:) must precede all host variables in an SQL statement

  2. B. A semi colon (;) must precede all host variables in an SQL statement

  3. C. We can use any variable directly

  4. D. None

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

When accessing DB2 database tables from a COBOL program, any host variable referenced inside an EXEC SQL block must be prefixed with a colon (:) to distinguish it from DB2 table column names. Using semicolons or omitting the prefix entirely will cause compilation errors.

Multiple choice technology mainframe
  1. A. 1B, 2E, 3A, 4C, 5D

  2. B. 1D, 2A, 3E, 4C, 5B

  3. C. 1E, 2D, 3B, 4A, 5C

  4. D. 1C, 2D, 3E, 4A, 5B

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

In DB2 SQL, -904 indicates a resource unavailable error, -818 represents a timestamp mismatch between plan and program, -181 indicates an invalid datetime format, -803 represents a duplicate key violation, and -911 indicates a deadlock or timeout. Option A matches all codes correctly.

Multiple choice technology mainframe
  1. (A) Have only Duplicate records from input to output

  2. (B) Remove Duplicates records and write as single instance in output

  3. (C) Have only non Duplicate records from input to output

  4. (D) None of the above

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

SUM FIELDS=NONE in JCL/SORT eliminates duplicate records by keeping only one instance when multiple records have matching sort keys. Unlike SUM FIELDS with numeric fields (which sums values), FIELDS=NONE simply discards duplicates, yielding unique records.

Multiple choice technology databases
  1. 3

  2. 4

  3. 1

  4. None

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

The SQL query uses concatenation (||) to combine address1, a comma, address2, another comma, and address2 again into a single column with alias 'Adress'. Regardless of how many source columns are concatenated, the result set contains exactly one column named 'Adress'.

Multiple choice technology databases
  1. Column

  2. 1966_Invoices

  3. #Invoices

  4. Catch_#22

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

In Oracle SQL (and most databases), unquoted column names must start with a letter, not a number. '1966_Invoices' starts with a number making it invalid. '#Invoices' starts with a special character. 'Catch_#22' is valid because it starts with a letter and contains only allowed characters (letters, digits, underscore, hash). 'Column' may be a reserved keyword but can be used as a column name without quoting in Oracle.

Multiple choice technology databases
  1. cursor CAPITALS is

  2. select CITY, STATE

  3. into my_city, my_state

  4. from CITIES where CAPITAL = 'Y';

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

In a cursor declaration, the INTO clause is not part of the SELECT statement. The INTO clause is used with explicit cursors only when combined with a FETCH statement to retrieve rows into variables. A cursor definition should only contain SELECT-FROM-WHERE (and other clauses like GROUP BY, ORDER BY), but not INTO.

Multiple choice technology databases
  1. When the datatypes of SELECT clause and INTO clause do not match

  2. When a SELECT statement returns more than one row

  3. When a SELECT statement returns no rows

  4. When INTO statement is missing in the SELECT statement

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

In PL/SQL, a SELECT INTO statement raises a NO_DATA_FOUND exception if it returns zero rows, and a TOO_MANY_ROWS exception if it returns more than one row. Mismatched datatypes raise different runtime errors, while a missing INTO clause is a syntax/compilation error rather than a raised runtime exception.

Multiple choice technology databases
  1. 10-JUL-00

  2. 17-JUL-00

  3. 12-JUL-00

  4. 11-JUL-00

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

The NEXT_DAY function returns the first occurrence of a given day of the week that is strictly after the input date. Since today (sysdate) is Monday, July 10, 2000, NEXT_DAY returns the following Monday, July 17, 2000. The to_char with 'DD-MON-RR' formats this as '17-JUL-00'. Note that RR handles year 2000 dates in a specific way.

Multiple choice technology databases
  1. No. of rows returned by SQL statement are HIGH

  2. No. of rows returned by SQL statement are FEW

  3. No. of rows returned by SQL statement are > 10000

  4. No. of rows returned by SQL statement are > 50000

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

High selectivity in SQL means the query predicate filters out most rows, returning only a FEW rows from the table. Selectivity is the ratio of rows returned to total rows - high selectivity means a small ratio (few rows), which is good for index usage. Low selectivity means many rows are returned, often making full table scans more efficient.

Multiple choice technology databases
  1. Avoid full table scan

  2. Avoid index scan

  3. Avoid network traffic

  4. Avoid cartesian join

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

SELECT * should be avoided because: 1) it can cause unnecessary full table scans when only specific columns are needed (option A), and 2) it retrieves all columns, increasing network traffic between database and application (option C). Using SELECT * doesn't inherently cause index scans (actually often prevents them) or cartesian joins.

Multiple choice technology
  1. AXA_AUGEO_TASKS_CURR_STATUS

  2. AXA_AUGEO_TASKS_FLOW

  3. Both a and b

  4. None of the above

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

When an AXA_RT_Application_Demand request type integrated with Augeo is created, records are inserted into both Augeo custom tables: AXA_AUGEO_TASKS_CURR_STATUS (for tracking current status) and AXA_AUGEO_TASKS_FLOW (for tracking workflow/flow information). This dual-table approach maintains both status and flow state for integration purposes.

Multiple choice technology
  1. KCRT_REQUESTS

  2. KCRT_REQ_HEADER_DETAILS

  3. KCRT_REQUEST_DETAILS

  4. KCRT_REQUESTS_TYPES

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

In HP PPM's database schema, KCRT_REQUESTS, KCRT_REQ_HEADER_DETAILS, and KCRT_REQUEST_DETAILS are valid table names. However, KCRT_REQUESTS_TYPES is not a standard table name - the naming convention would typically use REQUEST_TYPE (singular) or a different naming pattern. This question tests knowledge of the actual PPM database schema.

Multiple choice technology
  1. 'Primary Business Approver:' in the 'Application' section in 'AXA_RT_Application_Definition'

  2. 'Business Approvers:' in the 'Application' section in 'AXA_RT_Application_Definition'

  3. 'Business Approvers:' in the 'Line of Business' section in 'AXA_RT_LOB_Definition'

  4. 'Business Approvers:' in the 'Security' section in 'AXA_RT_Application_Demand'

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

The default value for 'Business Approver' in AXA_RT_Application_Demand's Ownership section inherits from 'Primary Business Approver' in AXA_RT_Application_Definition's Application section. This represents a parent-child relationship where application definition settings flow down to specific demand requests.

Multiple choice technology mainframe
  1. Foreign Key constraint

  2. Bind Issue

  3. Invalid date or Time

  4. Invalid string

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

SQL return code -180 indicates an invalid date or time specification. This error occurs when a date, time, or timestamp value does not conform to the expected format or contains invalid values.