Create a Trigger Function in PostgreSQL
📖 Scenario: You are managing a simple employee database. You want to keep track of when employee records are updated by automatically recording the update time.
🎯 Goal: Build a trigger function in PostgreSQL that updates a timestamp column whenever an employee record is modified.
📋 What You'll Learn
Create a table named
employees with columns id, name, and last_modifiedCreate a trigger function named
update_last_modified that sets last_modified to the current timestampCreate a trigger named
set_last_modified that calls the trigger function before any update on employees💡 Why This Matters
🌍 Real World
Automatically tracking when records are updated is common in business databases to maintain data accuracy and audit trails.
💼 Career
Database developers and administrators often create triggers to enforce business rules and automate data management tasks.
Progress0 / 4 steps