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
-
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.
-
False
-
This is hard to determine
-
True
-
None of the choices
C
Correct answer
Explanation
Oracle does support using comments to pass optimizer hints. These are specially formatted comments that tell the optimizer how to execute a query - for example, /*+ INDEX(table index_name) */ hints which index to use. This is a documented Oracle feature.
-
second
-
century
-
hour
-
year
-
date
-
month
A,B,C,D,E,F
Correct answer
Explanation
Oracle DATE type stores century, year, month, day, hour, minute, and second. All six components listed (A through F) are stored. Oracle DATE has no time zone information, but stores all the temporal components shown.
-
varchar is used to store fixed length character data, varchar2 is for variable length character data
-
varchar data type is not supported in oracle
-
varchar data type is applicable only to PL/SQL
-
maximum length for varchar is 2000 bytes and for varchar2 is 4000 bytes
D
Correct answer
Explanation
In Oracle, VARCHAR max length is 2000 bytes while VARCHAR2 max is 4000 bytes. VARCHAR is included only for backward compatibility and should not be used for new code. Both types work in SQL and PL/SQL, and both store variable-length character data.
-
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 defer checking until the transaction is committed. This allows temporary violations during intermediate transaction steps, which are resolved before the changes are permanently saved.
-
drop foreign keys
-
cascade constraints
-
this is not possible in oracle
-
clear references
B
Correct answer
Explanation
The CASCADE CONSTRAINTS clause in a DROP TABLE statement automatically drops any referential integrity constraints (foreign keys in child tables) that refer to primary or unique keys in the table being dropped.
-
No Rows retrieved
-
8 is displayed 20 times
-
8 is displayed 1 time
-
error message
B
Correct answer
Explanation
Selecting a literal constant like 8 from a table evaluates that constant for every row matching the query. Since the employee table contains 20 records, the number 8 is returned 20 times.
B
Correct answer
Explanation
In Oracle, a UNIQUE constraint allows multiple NULL values. Oracle treats NULL as incomparable (NULL != NULL), so each row with NULL in the unique column is considered distinct. This is standard SQL behavior.
-
specifies that the empty space created by deleting the records must be retained for this table and should not be used by other tables
-
specifies that the empty space created by deleting the records, can be used by other tables.
-
specifies that this transaction can be rolled back later
-
This clause cannot be used with truncate statement
A
Correct answer
Explanation
The REUSE STORAGE clause in TRUNCATE specifies that the space freed by deleting rows remains allocated to the table (kept in its tablespace). The default DROP STORAGE would return that space to the tablespace for other tables to use. TRUNCATE cannot be rolled back.
-
rowid
-
row_num
-
sl_no
-
rownum
-
sid
A,D
Correct answer
Explanation
In Oracle SQL, rowid (the unique physical address of a row) and rownum (the sequential order number of a retrieved row) are valid built-in pseudocolumns. row_num, sl_no, and sid are not standard pseudocolumns.