You are on page 1of 4

Test: Quiz: Creating DML Triggers: Part I 1.

We want to create a log record automatically every time any DML operati on is executed on either or both of the EMPLOYEES and DEPARTMENTS tables. What i s the smallest number of triggers that must be create to do this? Mark for Review (1) Points One Two (*) Three Six Eight

Correct 2. Which of the following are possible keywords for the timing component o f a trigger? (Choose three.) Mark for Review (1) Points (Choose all correct answers) BEFORE (*) INSTEAD WHENEVER INSTEAD OF (*) AFTER (*)

Correct 3. 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;

the transactions are rolled back because the update failed. the trigger will execute successfully Correct 4. Mark for Review (1) Points CREATE TRIGGER job_upd_trigg AFTER UPDATE ON employees(job_id) BEGIN . Refer to Section 13 Lesson 2. .Mark for Review (1) Points 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. 5. but the update fails because it violates a check constraint.. A BEFORE statement trigger inserts a row into a logging table every tim e a user updates the salary column of the employees table.. (*) One Three Four None of the above Incorrect. but not if a different column is updated. 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. The user now tries to update the salaries of three employees with a single UPDATE statement. The second line should be: AFTER DELETE OF DEPARTMENTS Nothing is wrong. How many rows will be inser ted into the logging table? Mark for Review (1) Points None.

True or False ? Mark for Review (1) Points True (*) False Correct 7.job_id BEGIN ... and when? Mark for Review (1) Points Once. A statement trigger is creat ed by: CREATE OR REPLACE TRIGGER emp_upd_trigg AFTER DELETE ON EMPLOYEES BEGIN . An AFTER UPDATE trigger can specify more than one column. CREATE TRIGGER job_upd_trigg AFTER UPDATE ON employees. (*) Correct 6.CREATE TRIGGER job_upd_trigg WHENEVER UPDATE OF job_id IN employees BEGIN . CREATE TRIGGER job_upd_trigg AFTER UPDATE OF job_id ON employees BEGIN . before the DELETE is executed Five times. A user now executes: DELETE FROM employees WHERE department_id = 50.. after the DELETE is executed (*) Six times... once after each row and once at the end of the statement . after each employee row is deleted Once.. How many times will the trigger fire... There are five employees in department 50.

. END. It does not matter. To do this. (*) It should be a BEFORE trigger because you cannot use RAISE_APPLICATION_E RROR with AFTER triggers. and why? Mark for Review (1) Points It should be a BEFORE trigger because if an AFTER trigger were created... It should be an AFTER trigger because the Oracle Server cannot fire the trigger until it knows that the employee has been deleted. the employee would already have been deleted by the time the trigger checks the date.Line A BEGIN IF TO_CHAR(SYSDATE'. END IF.The trigger will not fire at all Correct 8.. DELETE ON employees -.'Invalid delete').'DY') = 'SUN' THEN RAISE_APPLICATION_ERROR(-20101. either a BEFORE or an AFTER trigger could be created . Correct . Should this be a BEFORE or AFTER trigger... We want to prevent employees from being deleted on Sundays. we create the following trigger: CREATE OR REPLACE TRIGGER stop_del_emps .