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

Multiple choice technology databases
  1. VARCHAR2

  2. RECORD

  3. BOOLEAN

  4. RAW

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. In compiled form

  2. As source code

  3. Both A & B

  4. Not stored

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. will

  2. won't

  3. sometimes possible

  4. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. 3500,5000,2850

  2. 5000,2850

  3. 2850,5750

  4. 5000,5750

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. A piece of logic written in PL/SQL

  2. Executed at the arrival of a SQL event

  3. Both A & B

  4. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. Define, Create

  2. Insert, Update, Delete

  3. Drop, Comment

  4. All of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. INSERT

  2. UPDATE

  3. SELECT

  4. All of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. VARCHAR2

  2. RECORD

  3. BOOLEAN

  4. RAW

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. In compiled form

  2. As source code

  3. Both A & B

  4. Not stored

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. will

  2. won't

  3. sometimes possible

  4. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. 3500,5000,2850

  2. 5000,2850

  3. 2850,5750

  4. 5000,5750

Reveal answer Fill a bubble to check yourself
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).

Multiple choice technology databases
  1. A piece of logic written in PL/SQL

  2. Executed at the arrival of a SQL event

  3. Both A & B

  4. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. scott

  2. john

  3. sys

  4. system

Reveal answer Fill a bubble to check yourself
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