10B.68 Code an Oracle Database trigger to enforce the constraint that an employee can never change his or her department. 10B.69 Code an Oracle Database trigger to allow the deletion of a department...

1 answer below »
Please review and the question in the document using Oracle.


10B.68 Code an Oracle Database trigger to enforce the constraint that an employee can never change his or her department. 10B.69 Code an Oracle Database trigger to allow the deletion of a department if it has only one employee. Assign the last employee to the Human Resources department. Assume the trigger in Review Question 10B.68 has not been created. HINT: Due to Oracle Database “mutating table” issues, the best solution here is to create a view that is a copy of the DEPARTMENT table and base the trigger on that view. 10B.70 Design a system of triggers to enforce the M-M relationship. Use Figure 10B-72 as an example, but assume that departments with only one employee can be deleted. Assign the last employee in a department to Human Resources. HINTS: You will need four triggers, but one of them is the solution to Review Question 10B.69. Also, you may need to create views for some or all of the remaining three triggers.
Answered Same DayApr 15, 2021

Answer To: 10B.68 Code an Oracle Database trigger to enforce the constraint that an employee can never change...

Shivani answered on Apr 16 2021
145 Votes
10B.68 Code an Oracle Database trigger to enforce the constraint that an employee can never change his or her department.
Solution:
CREATE OR REPLACE TRIGGER TRGR_EMPLOYEE_NODEPTCHANGE
BEFORE UPDATE ON EMPLOYEE FOR EACH ROW
DECLARE
    EXEC_DEPT EXCEPTION;
    PRAGMA EXCEPTION_INIT(EXEC_DEPT, -20002);
    
    VAR_COUNT NUMBER;
BEGIN
    SELECT COUNT(*) INTO VAR_COUNT FROM DEPARTMENT DEPT
    WHERE DEPT.DEPARTMENT=:OLD.DEPARTMENT;
    IF (VAR_COUNT > 0) AND (:OLD.DEPARTMENT <> :NEW.DEPARTMENT) THEN
         RAISE EXEC_DEPT;
    END IF;
END;
10B.69 Code an Oracle Database trigger to allow the...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here