You are on page 1of 5

Test: Quiz: Creating DML Triggers: Part II 1. Which of the following best describes conditional predicates in a trigg er?

Mark for Review (1) Points They are special variables which must be DECLAREd within the trigger. They allow the trigger code to see what data values are being inserted i nto a row. They are automatically declared boolean variables which allow the trigge r body to detect which DML operation is being executed. (*) They are special cursor attributes, like %ROWCOUNT and %NOTFOUND

Correct 2. Examine the following code. To create a row trigger, what code should b e included at Line A? CREATE OR REPLACE TRIGGER del_emp_trigg BEFORE DELETE ON employees ---- Line A BEGIN ... Mark for Review (1) Points FOR EVERY ROW FOR EACH ROW (*) FOR EVERY ROW FOR ALL ROWS Nothing is needed because DML triggers are row triggers by default.

Correct 3. What is wrong with this compound trigger example? CREATE OR REPLACE TRIGGER compound_trigger FOR UPDATE OF salary COMPOUND TRIGGER threshold CONSTANT SIMPLE_INTEGER := 200; BEFORE EACH ROW IS BEGIN

-- some action END BEFORE EACH ROW; AFTER EACH ROW IS BEGIN -- some action END AFTER EACH ROW; AFTER STATEMENT IS BEGIN -- some action END AFTER STATEMENT; END compound_trigger; Mark for Review (1) Points Missing BEFORE timing statement. Missing the EXCEPTION section. Missing name of table on which the trigger fires. (*) Missing the INSTEAD OF timing section. Missing the BEFORE and INSTEAD OF timing sections.

Correct 4. What are the timing events for a compound trigger? (1) Points Mark for Review

Before the triggering statement; After the triggering statement; Instead of the triggering statement. Before the triggering statement; Before each row; After each row; After the triggering statement. (*) Before the triggering statement; After the triggering statement; After e ach row. Before the triggering statement; Before each row; After the triggering s tatement.

Correct 5. You decide to create the following trigger: CREATE OR REPLACE TRIGGER empl_trigg

BEFORE UPDATE ON employees BEGIN -- Line A RAISE_APPLICATION_ERROR('Cannot update salary'); ELSE INSERT INTO log_table values (USER, SYSDATE); END IF; END; You want the trigger to prevent updates to the SALARY column, but allow updates to all other columns. What should you code at Line A? Mark for Review (1) Points IF UPDATING SALARY THEN IF UPDATING('SALARY') THEN (*) IF UPDATE('SALARY') THEN IF UPDATING(SALARY) THEN IF UPDATE(SALARY) THEN

Correct 6. Whenever an employee's JOB_ID is updated, we want to insert a row into a logging table to record the employee_id and the new value of JOB_ID. We create a row trigger whose body includes the following code: BEGIN INSERT INTO logging_table (emp_id, job_id) VALUES -- Point A END; At point A, which of the following will insert the correct data into the logging table? (Choose two.) Mark for Review (1) Points (Choose all correct answers) (:OLD.employee_id, :OLD.job_id); (:OLD.employee_id, :NEW.job_id); (*) (:NEW.employee_id, :OLD.job_id);

(:NEW.employee_id, :NEW.job_id); (*) (NEW.employee_id, NEW.job_id);

Correct 7. Which of the following statements about INSTEAD OF triggers are NOT tru e? (Choose two.) Mark for Review (1) Points (Choose all correct answers) They can be created on a table. (*) They can be created on a simple view. They can be created on a complex view. They can be statement triggers. (*) They can be row triggers.

Correct 8. A row trigger has been created which is fired by UPDATE ON employees. A user now executes a single SQL statement which updates four rows of the EMPLOYE ES table. How many times will the row trigger fire? Mark for Review (1) Points Once Twice Four times (*) Five times Eight times

Correct 9. The following view and trigger have been created:

CREATE VIEW dept_view AS SELECT * FROM departments; CREATE OR REPLACE TRIGGER dept_view_trigg INSTEAD OF UPDATE ON dept_view BEGIN DBMS_OUTPUT.PUT_LINE('Sample Message'); END; Departments 50 and 80 exist but department 81 does not. A user now executes the following statement: UPDATE dept_view SET department_name = 'Sales' WHERE department_id IN (50,80,81); What happens? Mark for Review (1) Points Two rows are updated and "Sample Message" is displayed once. No rows are updated and "Sample Message" is displayed once. No rows are updated and "Sample Message" is displayed twice. (*) No rows are updated and "Sample Message" is displayed three times. None of the above.

Correct 10. The OLD and NEW qualifiers can be used with statement triggers as well as row triggers. True or False? Mark for Review (1) Points True False (*)

Correct

You might also like