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
-
VARCHAR2
-
RECORD
-
BOOLEAN
-
RAW
B
Correct answer
Explanation
VARCHAR2, BOOLEAN, and RAW are all scalar data types in PL/SQL, meaning they hold a single value. RECORD is a composite data type that can contain multiple fields (similar to a struct in other languages). This makes RECORD the odd one out because it's a composite type that can hold multiple values, while the others are simple scalar types holding single values. Therefore option B (RECORD) is correct.
-
In compiled form
-
As source code
-
Both A & B
-
Not stored
A
Correct answer
Explanation
Database procedures are stored in compiled form within the database. This compilation happens when the procedure is created, improving execution performance compared to interpreting source code each time. The database engine stores the compiled execution plan, not the original source.
-
will
-
won't
-
sometimes possible
-
None of the above
B
Correct answer
Explanation
A UNIQUE constraint prevents duplicate values in the column. If multiple rows are inserted with SYSDATE, they will have identical date-time values (down to the second) when inserted in rapid succession, causing constraint violations. Even if inserted at different times, the constraint will reject any duplicates, so it won't reliably accept all SYSDATE inserts.
-
3500,5000,2850
-
5000,2850
-
2850,5750
-
5000,5750
A
Correct answer
Explanation
This is a correlated subquery finding salaries where fewer than 3 other employees have lower salaries. Count employees with salary less than each E1.SAL: for 5750, count=4 (all others lower); for 5000, count=2; for 3500, count=1; for 2850, count=0. Condition 3 > count is true for salaries 5000, 3500, 2850 where count is 2, 1, 0 respectively.
-
A piece of logic written in PL/SQL
-
Executed at the arrival of a SQL event
-
Both A & B
-
None of the above
C
Correct answer
Explanation
A database trigger is a procedural block of logic written in PL/SQL (or another procedural language) that is automatically executed or fired by the database engine in response to a specified SQL event, such as an INSERT, UPDATE, or DELETE statement.
-
Define, Create
-
Insert, Update, Delete
-
Drop, Comment
-
All of the above
B
Correct answer
Explanation
Triggers are database objects that automatically execute in response to specific data manipulation events. The three primary DML events that can fire triggers are INSERT (when new rows are added), UPDATE (when existing rows are modified), and DELETE (when rows are removed). Options like Define, Create, Drop, and Comment are DDL operations, not trigger events.
-
INSERT
-
UPDATE
-
SELECT
-
All of the above
D
Correct answer
Explanation
DML (Data Manipulation Language) encompasses all SQL statements that manipulate data stored in database objects. The primary DML operations are INSERT (add new data), UPDATE (modify existing data), DELETE (remove data), and SELECT (retrieve/query data). All four options represent valid DML statements.
-
VARCHAR2
-
RECORD
-
BOOLEAN
-
RAW
B
Correct answer
Explanation
RECORD is the odd one out because it's a composite/structured data type that can hold multiple fields of different types (like a struct), while VARCHAR2, BOOLEAN, and RAW are all scalar/primitive data types that hold single values. RECORD is used in PL/SQL for defining complex data structures, not for storing individual values in columns.
-
In compiled form
-
As source code
-
Both A & B
-
Not stored
A
Correct answer
Explanation
Database procedures are stored in compiled form within the database. This compilation happens when the procedure is created, improving execution performance compared to interpreting source code each time. The database engine stores the compiled execution plan, not the original source.
-
will
-
won't
-
sometimes possible
-
None of the above
B
Correct answer
Explanation
A UNIQUE constraint prevents duplicate values in the column. If multiple rows are inserted with SYSDATE, they will have identical date-time values (down to the second) when inserted in rapid succession, causing constraint violations. Even if inserted at different times, the constraint will reject any duplicates, so it won't reliably accept all SYSDATE inserts.
-
3500,5000,2850
-
5000,2850
-
2850,5750
-
5000,5750
A
Correct answer
Explanation
The nested query counts how many employees have salary LESS than the current employee (E1.SAL > E2.SAL). The condition 3 > count(*) means we want salaries where at most 2 other salaries are lower. For 3500: only 2850 is lower (count=1). For 5000: 3500 and 2850 are lower (count=2). For 2850: none are lower (count=0). For 5750: three are lower (count=3, fails condition).
-
A piece of logic written in PL/SQL
-
Executed at the arrival of a SQL event
-
Both A & B
-
None of the above
C
Correct answer
Explanation
A trigger is indeed a piece of logic (typically written in PL/SQL in Oracle databases) that automatically executes in response to specific SQL events like INSERT, UPDATE, or DELETE operations on a table. Therefore both A and B are correct.
C
Correct answer
Explanation
To solve this question, the user needs to know about the DUAL table in Oracle databases.
The DUAL table is a one-row, one-column table that is automatically created by Oracle. It is owned by the SYS user and is accessible to all users.
Therefore, the correct answer is:
The Answer is: C. sys
A
Correct answer
Explanation
Triggers are dependent objects on the table they are created for. When a table is dropped, all associated triggers are automatically dropped as well because they cannot exist without the table. This is standard database behavior across most RDBMS platforms.
-
DDL
-
DML
-
DCL
-
None of the Above