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. 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
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.

Multiple choice technology programming languages
  1. 3,2,1

  2. 3,2,2

  3. 4,2,1

  4. 4,3,2

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

COUNT() counts all rows = 4. COUNT(c1+c2) counts non-null results - NULL+anything=NULL, and 2+0=2, 1+1=2, so only 2 rows have non-null sums. COUNT(DISTINCT(c1+c2)) counts distinct non-null values - both sums equal 2, so only 1 distinct value. Note: the row with NULL NULL is counted in COUNT() but not in the expression counts.

Multiple choice technology programming languages
  1. Employees who work for a department that is not listed in DEPT table.

  2. Employees who work from department 1

  3. Employees who work for a department with more than 1 employee

  4. Employees who work for a department other than department 1

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

NOT EXISTS returns true when the subquery returns no rows. This query selects employees where their department number doesn't exist in the DEPT table - meaning they're orphaned records with invalid department references. This is a common pattern for finding referential integrity violations. Options B, C, and D describe specific department conditions that don't match the NOT EXISTS logic.

Multiple choice technology databases
  1. FETCH

  2. EXTRACT

  3. GET

  4. SELECT

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

SELECT is the fundamental SQL statement used to query and retrieve data from database tables. It's the most commonly used SQL command and forms the basis of data extraction operations. Options like FETCH, EXTRACT, and GET are not standard SQL keywords for data retrieval.

Multiple choice technology databases
  1. DROP

  2. DELETE

  3. TRUNCATE

  4. REMOVE

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

DELETE is the DML statement used to remove specific rows from a database table based on conditions. DROP removes the entire table structure, TRUNCATE removes all rows but keeps the table structure, and REMOVE is not a standard SQL command. DELETE is the correct choice for removing data while preserving the table.

Multiple choice technology databases
  1. A piece of logic written in PL/SQL

  2. Executed at the arrival of a SQL*FORMS event

  3. Both A & B

  4. None of the above

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

A trigger is procedural code (PL/SQL in Oracle) that automatically executes in response to certain events on a table or view. The answer captures both aspects: it's written in PL/SQL (option A) and is executed by events (option B). Triggers are used to enforce business rules, maintain data integrity, and automate database tasks.