Computer Knowledge

Database and SQL

3,929 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 programming languages
  1. The UNIQUE constraint does not permit a null value for the column.

  2. The PRIMARY KEY and FOREIGN KEY constraints create a UNIQUE index.

  3. The NOT NULL constraint ensures that null values are not permitted for the column.

  4. A UNIQUE index gets created for columns with PRIMARY KEY and UNIQUE constraints.

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

The UNIQUE constraint allows null values (unless combined with NOT NULL). A UNIQUE index is automatically created for columns defined with PRIMARY KEY and UNIQUE constraints, making that statement correct, while NOT NULL ensures no nulls are allowed.

Multiple choice technology programming languages
  1. A subquery should retrieve only one row.

  2. A subquery can retrieve zero or more rows.

  3. Subqueries CANNOT be nested by more than two levels.

  4. A subquery can be used only in SQL query statements.

  5. A subquery CANNOT be used in an SQL query statement that uses group functions.

  6. When a subquery is used with an inequality comparison operator in the outer SQL statement,

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

Subqueries can return zero, one, or multiple rows depending on context and operators used (B is true, disproving A). They can be nested beyond two levels in most databases (C is false). Subqueries can appear in various SQL statement types including DML and DDL, not just queries (D is false). They work with group functions (E is false). When using inequality operators with subqueries, single-row subqueries must be ensured or the ANY/ALL modifiers must be used (F is true, describing the inequality constraint requirement).

Multiple choice technology programming languages
  1. USER_CONSTRAINTS

  2. USER_OBJECTS

  3. ALL_CONSTRAINTS

  4. USER_CONS_COLUMNS

  5. USER_COLUMNS

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

USER_CONS_COLUMNS displays the columns that participate in constraints defined on tables owned by the current user. USER_CONSTRAINTS shows constraint definitions but not column details. USER_OBJECTS lists all objects owned by the user. ALL_CONSTRAINTS includes constraints on accessible objects owned by others. USER_COLUMNS shows all table columns, not specifically constraint-related ones.

Multiple choice technology programming languages
  1. GRANT select ON dept TO ALL_USERS;

  2. GRANT select ON dept TO ALL;

  3. GRANT QUERY ON dept TO ALL_USERS

  4. GRANT select ON dept TO PUBLIC;

  5. GRANT QUERY ON dept TO PUBLIC;

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

To grant all users query privileges, use GRANT select ON dept TO PUBLIC. PUBLIC is a reserved word that represents all database users. Option A incorrectly uses ALL_USERS which is not a valid grantee. Option B incorrectly uses ALL without PUBLIC. Option C incorrectly uses QUERY instead of SELECT and ALL_USERS. Option E incorrectly uses QUERY and incorrectly capitalizes PUBLIC.

Multiple choice technology programming languages
  1. UNIQUE

  2. NOT NULL

  3. CHECK

  4. PRIMARY KEY

  5. FOREIGN KEY

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

The NOT NULL constraint can only be defined at the column level because it applies to a single column's values. Constraints like UNIQUE, CHECK, PRIMARY KEY, and FOREIGN KEY can be defined at either the column level or table level. Table-level constraints allow specification across multiple columns, which is essential for composite keys and multi-column conditions.

Multiple choice technology programming languages
  1. The tables being joined have NOT NULL columns.

  2. The tables being joined have only matched data.

  3. The columns being joined have NULL values.

  4. The tables being joined have only unmatched data.

  5. The tables being joined have both matched and unmatched data.

  6. Only when the tables have a primary key/foreign key relationship.

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

Outer joins preserve all rows from one or both tables, filling in NULLs where there are no matches. Use them when you need to keep unmatched rows (like finding customers with no orders) or when NULL values in join columns indicate non-matches rather than missing data. Inner joins only return matched rows, so outer joins are essential when unmatched data matters.

Multiple choice technology databases
  1. INTEGER

  2. REAL

  3. NUMERIC (7,3)

  4. DECIMAL(10,3)

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

To store values up to 9999999.999, you need 7 digits before the decimal point and 3 digits after, requiring a total precision of 10. Thus, DECIMAL(10,3) is the correct data type.

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.