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
-
Cursor
-
Trigger
-
Sequence
-
View
A
Correct answer
Explanation
PL/SQL packages can group related program units including procedures, functions, cursors, and variables. Option A (Cursor) is correct - cursors CAN be declared in a package specification. Triggers (B), Sequences (C), and Views (D) are standalone schema objects that CANNOT be part of packages.
-
Use a drop procedure statement to drop a standalone procedure.
-
Use a drop procedure statement to drop a procedure that is part of a package. Then recompile the package specification.
-
Use a drop procedure statement to drop a procedure that is part of a package. Then recompile the package body.
-
For faster removal and re-creation, do not use a drop procedure statement. Instead, recompile the procedure using the alter procedure statement with the REUSE SETTINGS clause.
A
Correct answer
Explanation
DROP PROCEDURE removes standalone procedures. Packaged procedures cannot be dropped individually - you must drop or recreate the entire package body. Option A is correct. Options B and C are wrong because DROP PROCEDURE doesn't work on packaged procedures. Option D is nonsense - REUSE SETTINGS doesn't exist and ALTER PROCEDURE doesn't remove procedures.
-
If errors occur during the compilation of a trigger, the trigger is still created.
-
If errors occur during the compilation of a trigger you can go into SQL *Plus and query the USER_TRIGGERS data dictionary view to see the compilation errors.
-
If errors occur during the compilation of a trigger you can use the SHOW ERRORS command within iSQL *Plus to see the compilation errors.
-
If errors occur during the compilation of a trigger you can go into SQL *Plus and query the USER_ERRORS data dictionary view to see compilation errors.
B
Correct answer
Explanation
The question asks which statement is FALSE. Options A, C, and D are TRUE - triggers with compilation errors are still created (as INVALID), and you CAN view errors via SHOW ERRORS or USER_ERRORS. Option B claims you can use USER_TRIGGERS to see compilation errors, which is FALSE - compilation errors are in USER_ERRORS, not USER_TRIGGERS.
-
The rows are selected and ordered.
-
The validity of the SQL statement is established.
-
An area of memory is established to process the SQL statement.
-
The SQL statement is run and the number of rows processed is returned.
D
Correct answer
Explanation
In dynamic SQL processing, the execute phase runs the actual SQL statement and returns the count of affected rows. For INSERT/UPDATE/DELETE, this is when data modification happens and row counts are returned. Selecting/ordering rows (A) happens for queries. Validity checking (B) is parse phase. Memory allocation (C) is define/prepare phase.
-
Trigger type
-
Trigger body
-
Trigger event
-
Trigger timing
A
Correct answer
Explanation
Trigger TYPE determines execution frequency. Row-level triggers fire once per ROW affected. Statement-level triggers fire once per STATEMENT regardless of rows. Trigger body (B) is the code executed. Trigger event (C) is what fires it (INSERT/UPDATE/DELETE). Trigger timing (D) is before/after/in stead-of.
-
USER_PROCEDURES
-
USER_PROCS
-
USER_OBJECTS
-
USER_PLSQL_UNITS
C
Correct answer
Explanation
USER_OBJECTS is the standard dictionary view containing LAST_DDL_TIME, which shows when any schema object (including procedures) was last compiled or modified. USER_PROCEDURES and USER_PROCS are not standard Oracle views. USER_PLSQL_UNITS may exist in some versions but USER_OBJECTS is the canonical source for compilation timestamps.
-
LEFT JOIN
-
RIGHT JOIN
-
FULL JOIN
-
SELF JOIN
A,B,C,D
Correct answer
Explanation
All four options are valid JOIN types in SQL. LEFT JOIN returns all rows from left table plus matching right table rows. RIGHT JOIN returns all rows from right table plus matching left table rows. FULL JOIN returns all rows when there's a match in either table. SELF JOIN joins a table to itself. All are standard SQL JOIN types.
A
Correct answer
Explanation
The UNION operator in SQL combines the result sets of two or more SELECT statements and automatically removes duplicate rows, selecting only distinct values by default. To retain duplicates, UNION ALL must be used. Therefore, the statement is true.
B
Correct answer
Explanation
Constraints can be added at table creation time using CREATE TABLE with constraints like PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, or NOT NULL. However, constraints can also be added AFTER table creation using ALTER TABLE statements, making the statement false.
-
Alternate Key
-
Foreign Key
-
Unique Key
-
Alias Key
B
Correct answer
Explanation
In relational database design, the primary key of a referenced table becomes a foreign key in the referencing table. The question is slightly ambiguous as the primary key itself is a primary key, but in the context of referencing, it acts as a foreign key. An alternate or alias key is incorrect.
-
COUNT()
-
GROUP BY()
-
SUM()
-
MAX()
C
Correct answer
Explanation
SUM() is the aggregate function that returns the total (sum) of values in a numeric column. COUNT() returns the number of rows, not a sum. GROUP BY is used for grouping rows, not aggregation. MAX() returns only the maximum value, not the total.
A
Correct answer
Explanation
In database systems, index names must be unique within a schema or table to avoid conflicts. This allows the database to uniquely identify which index to maintain or query when referenced by name in DDL or DML statements.
B
Correct answer
Explanation
In COBOL, index names used with table SEARCH operations CAN be manipulated using the SET verb. The SET statement allows you to increment, decrement, or set an index to a specific value, which is essential for controlling table traversal.
-
purchase_date
-
credit_card
-
null
-
credit_card & product_id
-
product_id
D
Correct answer
Explanation
Purchaser_Product is a junction table resolving a many-to-many relationship between Purchaser and Product. Its primary key must be the composite of both foreign keys (credit_card, product_id) to ensure each combination is unique and prevent duplicate purchaser-product associations. Neither credit_card nor product_id alone is sufficient.
-
COMMIT
-
MERGE
-
UPDATE
-
DELETE
-
CREATE
-
DROP
B,C,D
Correct answer
Explanation
DML (Data Manipulation Language) statements manipulate data: MERGE combines insert/update operations, UPDATE modifies existing rows, and DELETE removes rows. COMMIT is a transaction control statement (TCL). CREATE and DROP are DDL (Data Definition Language) statements that define schema structures, not manipulate data.