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
-
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.
-
rename table employee as employee_copy
-
rename employee to employee_copy
-
alter employee rename to employee_copy
-
alter table employee rename as employee_copy
-
alter table employee rename to employee_copy
B,E
Correct answer
Explanation
Oracle supports two valid syntaxes for renaming tables: (1) RENAME old_name TO new_name, and (2) ALTER TABLE old_name RENAME TO new_name. The 'AS' keyword is invalid in both syntaxes. ALTER without TABLE is also invalid.
-
Primary Key
-
Check
-
Unique
-
Not Null
-
Foreign Key
A,C
Correct answer
Explanation
When you create a Primary Key constraint, the database automatically creates a unique index to enforce the uniqueness requirement. Similarly, a Unique constraint also creates a unique index to ensure no duplicate values. Check constraints only validate data integrity rules, Not Null enforces presence of values, and Foreign Key creates relationships but not unique indexes.
-
PreparedStatement
-
ParameterizedStatement
-
ParameterizedStatement and CallableStatement
-
All kinds of Statements (i.e. which implement a sub interface of Statement)
A
Correct answer
Explanation
PreparedStatement is the JDBC Statement type designed for executing parameterized queries with placeholders (?). It precompiles SQL statements, allowing efficient reuse with different parameter values. Statement (basic) doesn't support parameters, and CallableStatement is for stored procedures. ParameterizedStatement is not a valid JDBC interface.
-
You can use them to store long text strings
-
They have many of the characteristics of VARCHAR2 columns
-
They store variable-length character strings containing up to 2 gigabytes
-
None of the choices.
A,B,C
Correct answer
Explanation
Oracle LONG columns are used to store variable-length character strings containing up to 2 gigabytes of text. They share many characteristics with VARCHAR2 columns, although they have many more restrictions on usage.
-
TIMESTAMP WITH LOCAL TIME ZONE
-
TIMESTAMP
-
TIMESTAMP WITH TIME ZONE
-
DATE
A,B,C,D
Correct answer
Explanation
Oracle supports several datetime datatypes, including DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, and TIMESTAMP WITH LOCAL TIME ZONE. All four options represent valid built-in datetime types in Oracle SQL.
-
primary keys
-
sales figures
-
foreign keys
-
unique keys
A,D
Correct answer
Explanation
Database sequences generate unique numeric values often used for primary keys and unique keys to provide automatically incrementing identifiers. Sequences are not typically used for sales figures (which are data values, not identifiers) or foreign keys (which reference existing primary keys). The generated values ensure uniqueness across rows.