Oracle Database Quiz Questions

Course Name:Oracle
Chapter Name:Chapter 9 - Advanced Topics
Lesson Content Link:DB Trigger
Current Quiz Count:30
Progress
0%
Q1
True / False

In ORACLE, a trigger is a PL/SQL block that automatically executes in response to specific events on a table or view.

Q2
True / False

In ORACLE, triggers can only be set to fire before an event occurs.

Q3
True / False

In ORACLE, a trigger can only be associated with one table.

Q4
True / False

In ORACLE, triggers can be used to enforce complex business rules that cannot be enforced by constraints alone.

Q5
True / False

In ORACLE, it is possible to create a trigger that fires for each row affected by a DML statement.

Q6
True / False

In ORACLE, triggers cannot call stored procedures.

Q7
True / False

In ORACLE, you can create a trigger that fires for DDL events, such as CREATE or ALTER statements.

Q8
True / False

In ORACLE, a trigger can be defined to execute after a database startup event.

Q9
True / False

In ORACLE, the WHEN clause in a trigger definition allows conditional execution of the trigger logic.

Q10
True / False

In ORACLE, mutating table errors occur when a row-level trigger tries to read or modify a table that is currently being modified by the statement that fired the trigger.

Q11
Multiple Choice

Identify the SQL statements that correctly create a simple BEFORE INSERT trigger in Oracle.

SQL Code
CREATE OR REPLACE TRIGGER before_insert_employee
BEFORE INSERT ON employees
FOR EACH ROW
BEGIN
 :NEW.created_at := SYSDATE;
END;
Q12
Multiple Choice

Select the SQL statements that correctly create an AFTER UPDATE trigger in Oracle.

Q13
Multiple Choice

Determine the SQL statements that demonstrate the creation of a BEFORE DELETE trigger in Oracle.

Q14
Multiple Choice

Identify the SQL statements that correctly create a compound trigger in Oracle.

Q15
Multiple Choice

Choose the SQL statements that correctly create an INSTEAD OF trigger on a view in Oracle.

Q16
Multiple Choice

Which SQL statements demonstrate the creation of a trigger with conditional logic based on OLD and NEW values in Oracle?

Q17
Multiple Choice

Determine the SQL statements that correctly create a trigger to enforce a business rule in Oracle.

Q18
Multiple Choice

Identify the SQL statements that demonstrate the creation of a trigger that handles mutating table errors in Oracle.

Q19
Multiple Choice

Choose the SQL statements that correctly create a trigger with a PRAGMA AUTONOMOUS_TRANSACTION directive in Oracle.

Q20
Multiple Choice

Select the SQL statements that demonstrate the creation of a trigger that updates related tables in Oracle.

Q21
Single Choice

How would you create a trigger to automatically update a timestamp column whenever a row is updated in a table?

SQL Code
CREATE OR REPLACE TRIGGER update_timestamp
BEFORE UPDATE ON employees
FOR EACH ROW
BEGIN
 :NEW.last_updated := SYSDATE;
END;
Q22
Single Choice

Which type of trigger would you use to enforce a business rule that prevents salary increases of more than 20%?

SQL Code
CREATE OR REPLACE TRIGGER check_salary_increase
BEFORE UPDATE OF salary ON employees
FOR EACH ROW
WHEN (NEW.salary > OLD.salary * 1.2)
BEGIN
 RAISE_APPLICATION_ERROR(-20001, 'Salary increase exceeds 20%');
END;
Q23
Single Choice

How can you create a trigger to log changes to a specific column in a separate audit table?

SQL Code
CREATE OR REPLACE TRIGGER log_salary_changes
AFTER UPDATE OF salary ON employees
FOR EACH ROW
BEGIN
 INSERT INTO salary_audit (employee_id, old_salary, new_salary, change_date)
 VALUES (:OLD.employee_id, :OLD.salary, :NEW.salary, SYSDATE);
END;
Q24
Single Choice

What type of trigger would you create to automatically populate a full name column when inserting data into a table?

SQL Code
CREATE OR REPLACE TRIGGER populate_full_name
BEFORE INSERT ON employees
FOR EACH ROW
BEGIN
 :NEW.full_name := :NEW.first_name || ' ' || :NEW.last_name;
END;
Q25
Single Choice

Which trigger would you use to prevent the deletion of rows in a specific table under certain conditions?

SQL Code
CREATE OR REPLACE TRIGGER prevent_deletion
BEFORE DELETE ON employees
FOR EACH ROW
WHEN (:OLD.job_title = 'Manager')
BEGIN
 RAISE_APPLICATION_ERROR(-20002, 'Cannot delete a manager');
END;
Q26
Single Choice

How would you create a trigger that fires after an insert operation and updates another table based on the inserted data?

SQL Code
CREATE OR REPLACE TRIGGER update_department_total
AFTER INSERT ON employees
FOR EACH ROW
BEGIN
 UPDATE departments SET total_employees = total_employees + 1
 WHERE department_id = :NEW.department_id;
END;
Q27
Single Choice

Which trigger would you use to enforce that a column value must be uppercase before inserting into the database?

SQL Code
CREATE OR REPLACE TRIGGER enforce_uppercase
BEFORE INSERT ON employees
FOR EACH ROW
BEGIN
 :NEW.last_name := UPPER(:NEW.last_name);
END;
Q28
Single Choice

How can you create a trigger to automatically generate a unique value for a primary key column?

SQL Code
CREATE OR REPLACE TRIGGER generate_employee_id
BEFORE INSERT ON employees
FOR EACH ROW
BEGIN
 SELECT employee_seq.NEXTVAL INTO :NEW.employee_id FROM dual;
END;
Q29
Single Choice

How would you create a trigger that fires before an update to enforce that a salary increase cannot exceed a specified amount?

SQL Code
CREATE OR REPLACE TRIGGER enforce_salary_increase_limit
BEFORE UPDATE OF salary ON employees
FOR EACH ROW
WHEN (NEW.salary > OLD.salary + 1000)
BEGIN
 RAISE_APPLICATION_ERROR(-20003, 'Salary increase exceeds the limit');
END;
Q30
Single Choice

Which trigger type would you use to execute a specific action after a database table is updated?

SQL Code
CREATE OR REPLACE TRIGGER audit_changes
AFTER UPDATE ON employees
FOR EACH ROW
BEGIN
 INSERT INTO audit_log (change_date, user_name, operation)
 VALUES (SYSDATE, USER, 'UPDATE');
END;