Why triggers automate responses
📖 Scenario: You manage a small online store database. You want to automatically record the time when a new order is added, without manually typing it every time.
🎯 Goal: Build a MySQL trigger that automatically sets the order_date to the current date and time when a new order is inserted.
📋 What You'll Learn
Create a table called
orders with columns order_id (integer primary key), customer_name (text), and order_date (datetime).Create a trigger called
set_order_date that runs before inserting a new row into orders.The trigger should set the
order_date column to the current timestamp automatically.Insert a sample order without specifying
order_date to test the trigger.💡 Why This Matters
🌍 Real World
Triggers help automate routine tasks in databases, like setting timestamps or enforcing rules, saving time and reducing errors.
💼 Career
Database developers and administrators use triggers to maintain data integrity and automate workflows without extra application code.
Progress0 / 4 steps