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. The application must release the row-level Share lock it holds and acquire an Update lock on the row

  2. The application must release the row-level Share lock it holds and acquire an Update lock on the table

  3. The row-level Share lock will automatically be converted to a row-level Up-date lock

  4. The row-level Share lock will automatically be escalated to a table-level Up-date lock

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

When an application holding a Share lock needs to update a row, DB2 automatically converts (promotes) the row-level Share lock to an Update lock. The application does not need to explicitly release and reacquire locks - lock conversion is handled transparently by the database manager. Option D is incorrect because escalation is to table-level locks, not row-level Update locks.

Multiple choice technology databases
  1. Restrict users' access to a subset of table data

  2. Ensure that rows inserted remain within the scope of a definition

  3. Produce an action as a result of a change to a table

  4. Provide users with an alternate view of table data

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

Views are used to restrict access to specific rows or columns (A), simplify complex queries (D), and ensure data integrity through CHECK OPTION (B). Producing an action in response to table changes is the purpose of triggers, not views. Views are passive queries - they select data but cannot execute procedural logic in response to changes.

Multiple choice technology databases
  1. Yes

  2. No

  3. It Depends

  4. None of the above

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

DB2 does not necessarily fetch all rows when opening a cursor. The behavior depends on cursor type and optimization - with a declared cursor, rows may be fetched one at a time as needed (FETCH operations), not all at once. The result set is materialized progressively, not entirely at cursor open time. This approach improves performance and reduces memory usage for large result sets.

Multiple choice technology databases
  1. VALUES degf_to_c(32)

  2. SELECT date, degf_to_c(temp) AS temp_c FROM temp_data

  3. CALL degf_to_c(32)

  4. Both a and b

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

Scalar functions in DB2 can be invoked using VALUES clause (A) for direct function calls returning a single value, or within a SELECT statement (B) to apply the function to each row. Option C (CALL) is used for stored procedures, not scalar functions. Option D is correct because both A and B demonstrate proper scalar function invocation syntax.

Multiple choice technology databases
  1. Schema

  2. Table

  3. Alias

  4. Both a & b

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

A schema is a collection of named database objects such as tables, views, and indexes. It provides a logical grouping and namespace for these objects. Tables are individual objects within a schema, not collections themselves. An alias is just an alternate name for an object.

Multiple choice technology databases
  1. Space Issues

  2. Data Issues

  3. No records found while querying the table

  4. Both a & b

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

B37 abend is a specific error code in mainframe systems indicating a DASD space issue - the dataset or work file has run out of space during SPUFI (SQL Processor Using File Input) execution. Data issues or missing records would result in different error codes like SQLCODEs, not B37.

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.