You are on page 1of 3

Test: Quiz: Creating DML Triggers - Part 1 Bekijk uw antwoorden, feedback en scores hieronder.

Een asterisk (*) geeft een goed antwoord aan. Section 1 (Beantwoord alle vragen in deze sectie.) 1. An AFTER UPDATE trigger can specify more than one column. True or False? Markeren voor nakijken (1) Punten

Waar (*) Niet waar Correct 2. Which of the following are possible keywords for the timing component of a trigger? (Choose three.) (Kies alle goede antwoorden.) BEFORE (*) INSTEAD WHENEVER INSTEAD OF (*) AFTER (*) Correct 3. We want to create a log record automatically every time any DML operation is executed on either or both of the EMPLOYEES and DEPARTMENTS tables. What is the smallest number of triggers that must be create to do this? One Two (*) Three Six Eight Correct 4. Which of the following is the correct syntax for creating a DML trigger associated with the EMPLOYEES table? The trigger must fire whenever an employee's JOB_ID is updated, but not if a different column is updated. CREATE TRIGGER job_upd_trigg AFTER UPDATE ON employees(job_id) BEGIN ... CREATE TRIGGER job_upd_trigg WHENEVER UPDATE OF job_id IN employees BEGIN ... CREATE TRIGGER job_upd_trigg AFTER UPDATE ON employees.job_id BEGIN ... CREATE TRIGGER job_upd_trigg AFTER UPDATE OF job_id ON employees BEGIN ... (*) Markeren voor nakijken (1) Punten Markeren voor nakijken (1) Punten Markeren voor nakijken (1) Punten

Correct 5. What is wrong with the following code? CREATE OR REPLACE TRIGGER mytrigg AFTER DELETE ON departments BEGIN INSERT INTO audit_table (who, when) VALUES (USER, SYSDATE); COMMIT; END; A DML trigger cannot itself contain a DML statement such as INSERT INTO audit_table You cannot use COMMIT inside a trigger. (*) The last line of code should be END mytrigg; The second line should be: AFTER DELETE OF DEPARTMENTS Nothing is wrong, the trigger will execute successfully Correct 6. A BEFORE statement trigger inserts a row into a logging table every time a user updates the salary column of the employees table. The user now tries to update the salaries of three employees with a single UPDATE statement, but the update fails because it violates a check constraint. How many rows will be inserted into the logging table? None, the transactions are rolled back because the update failed. (*) One Three Four None of the above Correct 7. There are five employees in department 50. A statement trigger is created by: CREATE OR REPLACE TRIGGER emp_upd_trigg AFTER DELETE ON EMPLOYEES BEGIN ... A user now executes: DELETE FROM employees WHERE department_id = 50; How many times will the trigger fire, and when? Once, before the DELETE is executed Five times, after each employee row is deleted Once, after the DELETE is executed (*) Six times, once after each row and once at the end of the statement The trigger will not fire at all Correct 8. We want to prevent employees from being deleted on Sundays. To do this, we create the following trigger: Markeren voor nakijken Markeren voor nakijken (1) Punten Markeren voor nakijken (1) Punten Markeren voor nakijken (1) Punten

(1) Punten CREATE OR REPLACE TRIGGER stop_del_emps ....... DELETE ON employees -- Line A BEGIN IF TO_CHAR(SYSDATE','DY') = 'SUN' THEN RAISE_APPLICATION_ERROR(-20101,'Invalid delete'); END IF; END; Should this be a BEFORE or AFTER trigger, and why? It should be a BEFORE trigger because if an AFTER trigger were created, the employee would already have been deleted by the time the trigger checks the date. (*) It should be a BEFORE trigger because you cannot use RAISE_APPLICATION_ERROR with AFTER triggers. It should be an AFTER trigger because the Oracle Server cannot fire the trigger until it knows that the employee has been deleted. It does not matter, either a BEFORE or an AFTER trigger could be created. Correct