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

Multiple choice technology databases
  1. Modify existing rows in a table.

  2. Add a new column in a table

  3. Both a & b

  4. None

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

DML (Data Manipulation Language) statements are used to manipulate data within existing table structures. Modifying rows (using UPDATE, INSERT, DELETE) is DML operation. Adding a column is DDL (Data Definition Language) because it changes the table structure, not just the data. The question tests understanding of DML vs DDL distinction.

Multiple choice technology databases
  1. ORDER

  2. SORT

  3. ORDER BY

  4. GROUP BY

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

The ORDER BY clause is used in SQL to sort the result set in ascending or descending order based on one or more columns. ORDER alone is not a valid clause - it must be followed by BY. SORT is not a standard SQL keyword for sorting results. GROUP BY is used for aggregation, not sorting.

Multiple choice technology databases
  1. I,III,II,IV

  2. I,II,III,IV

  3. II,IV,III,I

  4. II,I,IV,III

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

The standard execution and syntax order of clauses in a SQL SELECT statement is WHERE (I), followed by GROUP BY (II), then HAVING (III), and finally ORDER BY (IV). This ensures rows are filtered, grouped, groups are filtered, and then results are sorted.

Multiple choice technology databases
  1. FROM

  2. Columns defined by expression

  3. WHERE

  4. Both b & c

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

Views containing columns defined by expressions (calculated/computed columns) cannot be used directly for INSERT operations because the database cannot determine how to map values back to base table columns. The other options (FROM, WHERE) are standard SQL clauses that do not prevent data insertion through views.

Multiple choice technology programming languages
  1. %ROWTYPE

  2. %TYPE

  3. AS_COLUMN

  4. None of the above

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

The %TYPE attribute in PL/SQL allows you to declare a variable that automatically inherits the datatype of a specific column in a database table. This provides maintainability - if the column's datatype changes, variables using %TYPE automatically adapt without code modification.

Multiple choice technology programming languages
  1. TRUE

  2. FALSE

  3. Both

  4. None

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

Standard SQL does not have built-in procedural error handling mechanisms like try-catch blocks. While modern SQL implementations (PL/SQL, T-SQL) extend SQL with programming constructs for exception handling, pure SQL itself is a declarative language without explicit error handling facilities.

Multiple choice technology programming languages
  1. DELCARE and BEGIN

  2. DECALRE and EXCEPTION

  3. EXCEPTION and END

  4. BEGIN and END

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

A PL/SQL block consists of optional DECLARE and EXCEPTION sections, and mandatory BEGIN and END sections. The options contain typos ('DELCARE' or 'DECALRE'), but the concept identifies the DECLARE (spelled DECALRE here) and EXCEPTION clauses as the optional parts of the block structure.