Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Database Systems

2022-2023

Use APEX for the lab activities and company schema

Consider the COMPANY database provided in the previous assignment. Using the
syntax of Oracle triggers, create triggers to do the following:

Whenever an employee is deleted, delete the PROJECT tuples and DEPENDENT


tuples related to that employee, and if the employee manages a department or
supervises employees, set the Mgr_ssn for that department to NULL and set the
Super_ssn for those employees to NULL.
You are required to provide the trigger code, SQL statements to test the triggers and
screenshots of the database state of affected rows before and after executing trigger
test statements and an explanation of your logic.

Solution:

CREATE TRIGGER DELETE_IN_CASCADE


AFTER DELETE ON EMPLOYEE
FOR EACH ROW
BEGIN
DELETE FROM WORKS_ON
WHERE ESSN = OLD.SSN;
DELETE FROM DEPENDENT
WHERE ESSN = OLD.SSN;
UPDATE EMPLOYE
SET SUPERSSN = ‘null’
WHERE SUPERSSN = OLD.SSN;
END;

You might also like