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
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.
-
Employees who work for a department that is not listed in DEPT table.
-
Employees who work from department 1
-
Employees who work for a department with more than 1 employee
-
Employees who work for a department other than department 1
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.
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.
-
DROP
-
DELETE
-
TRUNCATE
-
REMOVE
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.
-
A piece of logic written in PL/SQL
-
Executed at the arrival of a SQL*FORMS event
-
Both A & B
-
None of the above
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.
-
Modify existing rows in a table.
-
Add a new column in a table
-
Both a & b
-
None
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.
-
ORDER
-
SORT
-
ORDER BY
-
GROUP BY
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.
-
I,III,II,IV
-
I,II,III,IV
-
II,IV,III,I
-
II,I,IV,III
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.
-
FROM
-
Columns defined by expression
-
WHERE
-
Both b & c
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.
A
Correct answer
Explanation
Teradata Fast Load supports loading into multiset tables, which by definition allow duplicate rows. Unlike set tables that enforce uniqueness, multiset tables accept duplicates, and Fast Load can load them without error.
-
%ROWTYPE
-
%TYPE
-
AS_COLUMN
-
None of the above
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.
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.
-
DELCARE and BEGIN
-
DECALRE and EXCEPTION
-
EXCEPTION and END
-
BEGIN and END
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.
B
Correct answer
Explanation
A ROLLBACK statement explicitly ends a transaction by undoing any uncommitted changes. Therefore, it is indeed used to close a transaction.
-
Some DML,PL/SQL statements
-
All DML,PL/SQL statements
-
Only PL/SQL statements
-
None of the Above