Skip to main content

Command Palette

Search for a command to run...

๐Ÿš€ Using Triggers in Oracle SQL (Automating Database Actions)

Updated
โ€ข2 min read
๐Ÿš€ 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.

1 views