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
-
DROP
-
DELETE
-
CASCADE
-
TRUNCATE
D
Correct answer
Explanation
The TRUNCATE command is a DDL operation that quickly deletes all rows from a table without logging individual row deletions in the rollback segment, unlike DELETE which writes to rollback.
-
Column
-
1966_Invoices
-
Catch_#22
-
#Invoices
-
None of the above
-
5392845.324
-
871039453.1
-
97234512.123
-
1234567.12
B
Correct answer
Explanation
NUMBER(10,2) means total 10 digits with 2 after decimal, so max 8 digits before decimal (10-2=8). Option B has 9 digits before the decimal (871039453), which exceeds the allowed precision and causes an error. Option C has 3 decimal places but only 8 integer digits, so it would round to 97234512.12 without error. Oracle rounds values that exceed scale but fits within precision, only errors when integer part exceeds allowed digits.
-
where
-
having
-
order by
-
none of the above
C
Correct answer
Explanation
Subqueries in SQL cannot use ORDER BY clause because subqueries return a set of rows used by the outer query, and the outer query determines the final ordering. However, subqueries can use WHERE for row filtering and HAVING for group filtering. ORDER BY is only allowed in the outermost query or in subqueries that use TOP/LIMIT/FETCH FIRST clauses (not in this question's context).
A
Correct answer
Explanation
The LENGTH function in Oracle returns the character count of its argument after converting it to a string. When passed -1, Oracle implicitly converts it to the string '-1', which contains 2 characters: the minus sign and the digit 1. The LENGTH function counts all characters including signs and decimal points. This is not an error - Oracle allows implicit type conversion from number to varchar2.
D
Correct answer
Explanation
COUNT(column_name) ignores NULL values and only counts non-NULL entries. With 14 total records and 1 NULL in MGR column, COUNT(MGR) returns 13, which is <14. COUNT(*) would return 14 because it counts all rows regardless of NULLs. The question tests understanding that aggregate functions like COUNT, SUM, AVG skip NULL values when operating on a specific column.
-
Composite primarykey
-
Not null
-
unique
-
check
A
Correct answer
Explanation
A composite primary key involves multiple columns and must be declared using table-level constraint syntax (outside the column definitions). Single-column constraints like NOT NULL, UNIQUE, and CHECK can be declared inline with the column. For example: CREATE TABLE foo (a INT, b INT, PRIMARY KEY (a,b)) - the PRIMARY KEY clause at table level creates a composite key. Inline column syntax cannot specify multiple columns for a single constraint.
-
The Constraint condition is never checked
-
The Constraint condition is checked only at the time of commiting the transaction
-
The Constraint condition is checked only for newly inserted rows and will not be checked for already existing rows in the table
-
The constraint condition is checked after a predefined time interval
B
Correct answer
Explanation
In Oracle, deferred constraints are validated only at transaction commit time, not after each DML operation. This allows intermediate constraint violations during transaction processing. Option A is incorrect because constraints ARE checked - just deferred. Option C describes behavior for initially deferred vs. immediate constraints. Option D is incorrect because there's no time-interval-based checking.
-
False
-
This is hard to determine
-
True
-
None of the choices
C
Correct answer
Explanation
In Oracle SQL, hints are passed to the optimizer using specially formatted comments starting with a plus sign, such as /*+ HINT */. Thus, the statement is true.
-
second
-
century
-
hour
-
year
-
date
-
month
A,B,C,D,E,F
Correct answer
Explanation
Oracle DATE type stores all components: century, year, month, day, hour, minute, and second. All six options are correct as DATE includes time information down to seconds.
-
where
-
having
-
order by
-
none of the above
C
Correct answer
Explanation
Standard SQL subqueries cannot contain an ORDER BY clause because a subquery defines an unordered set of rows. Clauses like WHERE and HAVING are perfectly valid inside subqueries.
A
Correct answer
Explanation
In Oracle SQL, the LENGTH function returns NULL when given a negative number input. When you execute 'SELECT length(-1) FROM dual', Oracle implicitly converts -1 to a string, but LENGTH(-1) evaluates to NULL, not the count of digits. This is specific Oracle behavior for the LENGTH function with negative numeric inputs.
D
Correct answer
Explanation
The COUNT(column) function ignores NULL values. Since one of the 14 records has a NULL value in the mgr column, COUNT(mgr) will return 13, which is less than 14.
-
Composite primarykey
-
Not null
-
unique
-
check
A
Correct answer
Explanation
In SQL, a composite primary key (primary key spanning multiple columns) must be declared using table-level constraint syntax. Column-level constraints apply to single columns only. NOT NULL (B), UNIQUE (C), and CHECK (D) can all be declared at column level. Only composite primary keys require the table CONSTRAINT syntax like CONSTRAINT pk_name PRIMARY KEY (col1, col2).
-
The Constraint condition is never checked
-
The Constraint condition is checked only at the time of commiting the transaction
-
The Constraint condition is checked only for newly inserted rows and will not be checked for already existing rows in the table
-
The constraint condition is checked after a predefined time interval
B
Correct answer
Explanation
Deferred constraints in Oracle are checked only when the transaction is committed, not immediately after each DML statement. This allows temporary violations during a transaction as long as constraints are satisfied by commit time. Option A is false - constraints ARE checked. Option C describes a validated constraint, not deferred. Option D is false - there is no time interval-based checking.