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 databases
  1. Primary key access

  2. Access via unique index

  3. Table access by ROWID

  4. Full table scan

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

ROWID is the direct physical address of a row's location on disk, making it the fastest access method. Primary key and unique index accesses require an index lookup first, then ROWID access. Full table scan reads every row in the table, making it the slowest method.

Multiple choice technology databases
  1. SQL cannot support object-orientation

  2. The same query can be written in many ways, each with vastly different execution plans.

  3. SQL syntax is too difficult for non-computer professionals to use

  4. SQL creates excessive locks within the database

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

SQL's declarative nature allows the same query to be written in multiple syntactically different ways, which can result in vastly different execution plans and performance. This is a well-known challenge in SQL optimization. SQL does support object-oriented features through extensions, its syntax is widely used by non-programmers, and locking behavior is configurable.

Multiple choice technology programming languages
  1. True

  2. False

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

SEARCH operations do not require an index - a database can perform a full table scan to find matching rows. However, searches are much faster and more efficient with an index. Without an index, the database must examine every row in the table, which is slow for large tables but still functional.

Multiple choice technology databases
  1. before performing an export/import

  2. immediately after an upgrade or applying a maintenance pack

  3. converting to multiple organizations or multiple reporting currencies

  4. after a patch or multiple patches are applied

  5. whenever you receive a run-time error that suggests that a problem is caused by the AD_DDL package

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

Running validation on the APPS schema is most critical after applying patches (when schema changes are most likely) and when encountering run-time errors suggesting AD_DDL package issues (indicating potential corruption). The other options like before export/import or during organizational conversion are not the primary validation triggers - validation should be done after changes, not before them.

Multiple choice technology mainframe
  1. True

  2. False

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

DECLARE TABLE in DCLGEN is not mandatory because programmers can manually write host variable declarations in their COBOL or PL/I programs. DCLGEN is a convenience tool that generates declarations automatically, but it's optional.

Multiple choice technology mainframe
  1. SELECT statement has resulted in retrieval of more than one row

  2. AUTHORIZATION FAILURE

  3. consistency tokens in the DBRM and the load module are different

  4. NONE OF THE ABOVE

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

In DB2 SQL, the SQLCODE -922 indicates an authorization failure, typically signifying that the user does not have permission to perform the requested operation or connect to the plan.

Multiple choice technology mainframe
  1. True

  2. False

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

DECLARE CURSOR is a declarative SQL statement, not executable. It only defines the cursor and its associated SELECT statement for later use. The actual execution happens when you OPEN the cursor, not when you declare it.

Multiple choice technology mainframe
  1. True

  2. False

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

In DB2 and many other SQL implementations, subqueries cannot directly contain UNION operations. This is a syntax restriction. To combine results from multiple queries within a subquery, you would typically need to use alternative approaches like UNION ALL in a derived table or restructure the query.

Multiple choice technology mainframe
  1. 531

  2. 530

  3. 513

  4. 533

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

SQLCODE -530 in DB2 indicates a foreign key constraint violation. This error occurs when you try to insert or update a child row with a foreign key value that doesn't exist in the parent table, or when deleting a parent row that has dependent child rows.

Multiple choice technology programming languages
  1. 0

  2. 2

  3. error

  4. 1

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

The INSERT statement uses incorrect syntax - it should use VALUES keyword: INSERT INTO temp VALUES ('abc',100). Without VALUES, Oracle will throw a syntax error. The savepoint and rollback to savepoint would work correctly if the INSERT syntax was proper, but the error occurs before any savepoint operations.

Multiple choice technology programming languages
  1. inner join and intersect are same

  2. left join and union are same

  3. inner join when used with distinct can simulate intersect

  4. inner join and union are same

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

INTERSECT returns rows common to both queries. INNER JOIN returns matching rows from both tables based on a join condition. When you add DISTINCT to INNER JOIN, it removes duplicates, making it functionally equivalent to INTERSECT if the join conditions match on all columns. The other options are incorrect - UNION combines all rows (including duplicates), and joins are not equivalent to basic set operations.

Multiple choice technology programming languages
  1. delete from table_name where rowid not in (select max(rowid) from table group by duplicate_values_field_name);

  2. delete from table_name where rowid in (select max(rowid) from table group by duplicate_values_field_name);

  3. c)delete from table_name where rowid not in (select max(rowid) from table);

  4. delete from table_name where rowid not in (select rowid from table group by duplicate_values_field_name);

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

To delete duplicates, you keep one instance (usually the one with max rowid) and delete the rest. Option A correctly identifies rows where rowid is NOT IN the maximum rowid for each duplicate group. Options B and C would keep the wrong records or delete all records. Option D is incorrect because selecting rowid directly without an aggregate in the GROUP BY clause won't identify the max per group.

Multiple choice technology programming languages
  1. select * from emp where (rowid,1) in (select rowid, mod(rownum,2) from emp);

  2. select * from emp where (rowid,0) in (select rowid, mod(rownum,2) from emp);

  3. select * from emp where (rowid,1) in (select rowid, mod(rownum,1) from emp);

  4. select * from emp where (rowid,1) in (select rowid, mod(rownum,3) from emp);

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

MOD(rownum,2) returns 1 for odd-numbered rows (1,3,5...) and 0 for even-numbered rows (2,4,6...). By checking if (rowid,1) exists in the subquery that pairs each rowid with mod(rownum,2), we select only rows where rownum is odd. Option B checks for 0 (even rows), Option C uses mod(rownum,1) which is always 0, and Option D uses mod(rownum,3) which doesn't identify odd/even.

Multiple choice technology programming languages
  1. Change line 1 to read "SELECT DISTINCT bus_name, profits "

  2. Change line 3 to read "where city IN ("

  3. Change line 5 to read "where max (city) LIKE 'NOID%' "

  4. Change line 7 to read "order by city , profits desc "

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

When a subquery returns multiple rows, using the equals operator (=) causes an error. Changing to IN allows matching against any value in the returned set. Option A's DISTINCT would affect duplicates but not the multi-row error. Option C's MAX would change the logic to only match one city. Option D's ORDER BY change doesn't address the core issue.