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
-
AVG
-
COUNT
-
MAX
-
STDDEV
-
LENGTH
-
All the above.
A,B,C,D
Correct answer
Explanation
SQL GROUP functions (also called aggregate functions) perform calculations on sets of rows and return a single result. AVG, COUNT, MAX, and STDDEV are all GROUP functions that compute statistics across multiple rows. LENGTH, however, is a single-row function that operates on individual string values, not groups. The option 'All the above' is incorrect because it includes LENGTH which doesn't belong to GROUP functions.
B
Correct answer
Explanation
In Oracle SQL, the UNIQUE and BITMAP keywords cannot be used together when creating an index. UNIQUE enforces that all index key values must be distinct, while BITMAP creates a bitmap index optimized for low-cardinality columns with few distinct values. These are fundamentally different index types with different use cases, so they're mutually exclusive. You must choose one or the other, not both.
-
Adds all the numbers in a range of cells.
-
Adds up cell values based on a condition.
-
Returns a subtotal in a list or database.
-
None of the above.
B
Correct answer
Explanation
SUMIF adds values that meet a specified condition, unlike SUM which adds all values unconditionally. It requires a range to test, a criteria to match, and an optional range to sum.
-
Unique constraints
-
Primary keys
-
Cascading actions
-
Foreign keys
A
Correct answer
Explanation
Referential integrity ensures relationships between tables remain consistent. Primary keys, foreign keys, and cascading actions (like ON DELETE CASCADE) are core mechanisms for this. Unique constraints ensure data uniqueness but do not inherently manage relationships between different tables.
-
A View of a table
-
an alternate name for a table
-
A Secondary table
-
A Primary table
A,B
Correct answer
Explanation
In database terminology, a synonym is an alternate name for a database object like a table. It can function as a view-like alias (option A) or simply as an alternative reference name (option B). It is not a separate table, primary or secondary.
-
The relation of the primary key of a base table with foreign key of the reference table is known as referential integriety.
-
The relation of the secondary key of a base table with foreign key of the reference table is known as referential integriety.
-
The relation of the primary key of a secondary table with foreign key of the reference table is known as referential integriety.
-
The relation of the primary key of a base table with index key of the reference table is known as referential integriety.
A
Correct answer
Explanation
Referential integrity is a database concept that ensures relationships between tables remain consistent. It is maintained by defining a Foreign Key in a child (reference) table that must match a Primary Key in the parent (base) table, ensuring no orphaned records exist.
B
Correct answer
Explanation
The OTHERWISE clause in a SELECT instruction is optional, not mandatory. It provides a default case when no WHEN conditions match, but can be omitted if not needed. The statement claims it should be specified, which is false.
A
Correct answer
Explanation
In PL/SQL, every block (anonymous blocks, procedures, functions, and packages) can have its own EXCEPTION section to handle errors that occur within that specific block. This allows for modular error handling where different blocks can manage exceptions differently based on their context.
-
Type of Exception
-
Finally block
-
An Error Code
-
A message
A,C,D
Correct answer
Explanation
PL/SQL exception messages contain three key components: the exception type (such as NO_DATA_FOUND or VALUE_ERROR), an error code (numeric identifier like ORA-01403), and a descriptive message explaining the error. A FINALLY block is a separate construct used in some languages for cleanup code but is not part of the exception message itself in PL/SQL.
-
Named System Exceptions
-
Unnamed System Exceptions
-
Implicit Exceptions
-
Explicit Exceptions
-
User-defined Exceptions
A,B,E
Correct answer
Explanation
PL/SQL exceptions are categorized into three types: Named System Exceptions (pre-defined by Oracle), Unnamed System Exceptions (handled via Pragma EXCEPTION_INIT), and User-defined Exceptions (declared by the developer for specific business logic). 'Implicit' and 'Explicit' refer to how they are raised, not their type.
-
Not Declared explicitly
-
Raised implicitly when a predefined Oracle error occurs
-
caught by referencing the standard name within an exception-handling routine
-
All of the above
-
None of the above
D
Correct answer
Explanation
Named system exceptions in PL/SQL (like NO_DATA_FOUND, TOO_MANY_ROWS, DUP_VAL_ON_INDEX) are predefined exceptions that don't require explicit declaration, are raised automatically when specific Oracle errors occur, and are caught by referencing their standard names in exception handlers. These are built into the PL/SQL language for common error conditions.
A
Correct answer
Explanation
Pragma EXCEPTION_INIT is used to associate a user-defined exception name with a specific internal Oracle error number (ORA-nnnnn). This allows the programmer to write an explicit 'WHEN' handler for an error that doesn't have a pre-defined name in PL/SQL.
-
DECLARE
-
RAISE
-
PRAGMA
-
INITIATE
B
Correct answer
Explanation
In PL/SQL, user-defined exceptions must be explicitly raised using the RAISE statement when the error condition occurs. Unlike predefined exceptions that are raised automatically by Oracle, your custom exceptions need manual triggering with RAISE exception_name;. This allows controlled error handling for application-specific conditions.
-
Hardware failures
-
Design faults
-
Coding mistakes
-
None of the above
-
All of the above
E
Correct answer
Explanation
Run-time errors can originate from multiple sources including hardware failures (disk crashes, memory errors), design faults (logic errors, incorrect requirements interpretation), and coding mistakes (syntax errors, boundary violations). The most comprehensive answer recognizes that all these categories contribute to run-time error conditions.
-
internal, explicitly
-
internal, implicitly
-
user-defined, explicitly
-
user-defined, implicitly
B
Correct answer
Explanation
Internal exceptions (like NO_DATA_FOUND or ZERO_DIVIDE) are raised implicitly by the Oracle runtime engine whenever a program violates a database rule. User-defined exceptions, conversely, are typically raised explicitly by the programmer using the RAISE statement.