๐ Using Triggers in Oracle SQL (Automating Database Actions)

As part of my continued learning with Oracle Autonomous Database, I explored how triggers can be used to automate database actions. Triggers allow us to automatically execute logic when certain events occur in the database.
๐ฏ Objective
The goal of this activity was to:
Understand what triggers are Automate actions after data insertion Improve database functionality
๐ป Step 1: Creating Tables
CREATE TABLE employees (
emp_id NUMBER,
emp_name VARCHAR2(50),
salary NUMBER );
CREATE TABLE employee_log (
log_id NUMBER GENERATED ALWAYS AS IDENTITY,
message VARCHAR2(200) );
โ๏ธ Step 2: Creating a Trigger
CREATE OR REPLACE TRIGGER log_employee_insert AFTER INSERT ON employees
FOR EACH ROW BEGIN INSERT INTO employee_log(message)
VALUES ('New employee added: ' || :NEW.emp_name);
END;
๐งช Step 3: Inserting Data
INSERT INTO employees
VALUES (1, 'Ali', 50000);
INSERT INTO employees
VALUES (2, 'Sara', 60000);
๐ Step 4: Viewing Trigger Result
SELECT * FROM employee_log;
This shows automatically generated log entries.
๐ก What I Learned
How triggers automate database actions Using AFTER INSERT triggers Managing event-driven database logic
๐ Conclusion
This activity helped me understand how triggers can be used to automate operations inside the database. Triggers are widely used in real-world applications for logging, validation, and automation.




