Sunteți pe pagina 1din 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;

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; The second line should be: AFTER DELETE OF DEPARTMENTS Nothing is wrong, the trigger will execute successfully

Correct 4. A BEFORE statement trigger inserts a row into a logging table every tim e 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 inser ted into the logging table? Mark for Review (1) Points None, the transactions are rolled back because the update failed. (*) One Three Four None of the above

Incorrect. Refer to Section 13 Lesson 2. 5. 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. Mark for Review (1) Points 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 ... (*)

Correct 6. An AFTER UPDATE trigger can specify more than one column. True or False ? Mark for Review (1) Points True (*) False

Correct 7. There are five employees in department 50. A statement trigger is creat ed 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? Mark for Review (1) Points 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: 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? Mark for Review (1) Points 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_E RROR 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

S-ar putea să vă placă și