DBMS Week-6 Assignment
DBMS Week-6 Assignment
Background
table that
stores key details like name, job title, department, salary, and employment date. To ensure data
integrity,
accountability, and real-time notifications of critical changes, the organization wants to automate
certain
Objectives
1. Audit Log: Track every INSERT and UPDATE operation on the employees table. This is useful for
data audits,
especially for fields like salary and job_title, which have compliance and business significance.
salary is updated
Database Schema
The primary tables involved are as follows:
name VARCHAR(100),
job_title VARCHAR(50),
department VARCHAR(50),
employment_date DATE,
last_modified TIMESTAMP
);
employee_id INT,
operation_type VARCHAR(10),
modified_column VARCHAR(50),
old_value VARCHAR(100),
new_value VARCHAR(100),
);
1. AFTER INSERT Trigger: Logs the INSERT event to the audit_log table.
2. AFTER UPDATE Trigger: Logs any changes made to sensitive fields (e.g., salary, job_title) in the
audit_log,
updates the last_modified column, and triggers an email notification if the salary exceeds a
threshold.
Trigger Implementation
This trigger captures every new employee addition and logs it in the audit_log table.
BEGIN
END;
Explanation: This AFTER INSERT trigger logs a new record when a new employee is added, with
operation_type as INSERT.
Here, modified_column is set to 'ALL' to denote that an entire row was inserted.
This trigger logs specific changes in the employees table and manages updates to the last_modified
column.
Additionally, it checks if the new salary exceeds $100,000 and sends an alert if it does.
BEGIN
new_value)
', NEW.salary,
END IF;
END IF;
new_value)
END IF;
END;
Benefits:
- Automatic Auditing: The trigger-based solution ensures an audit trail for every change, enhancing
accountability.
- Timely Notifications: The notification alert system keeps HR informed about significant salary
updates in real-time.
- Data Consistency: The automatic update of the last_modified column ensures that the modification
timestamps are
Challenges:
- Performance Overhead: Frequent updates can create performance bottlenecks due to the trigger's
execution overhead,
execute automatically
Conclusion
Using triggers for INSERT and UPDATE operations in the employees table allowed the organization
to implement essential
functionality like auditing, notifications, and timestamp updates automatically. This solution provided
the necessary
tools to maintain data integrity, track changes efficiently, and enable real-time alerts for critical
updates, making