Create an INSERT Trigger to Log New Orders
📖 Scenario: You manage an online store database. You want to keep track of every new order placed by customers by automatically recording details into a separate log table.
🎯 Goal: Build an INSERT trigger on the orders table that automatically inserts a record into the order_log table whenever a new order is added.
📋 What You'll Learn
Create a table called
orders with columns order_id (integer), customer_name (varchar), and order_total (decimal).Create a table called
order_log with columns log_id (integer, auto-increment), order_id (integer), and log_message (varchar).Create an
INSERT trigger named log_new_order on the orders table.The trigger should insert a log entry into
order_log with the order_id and a message like 'New order added'.💡 Why This Matters
🌍 Real World
Automatically logging changes in a database helps keep track of important events without manual effort.
💼 Career
Database triggers are commonly used in real jobs to enforce business rules and audit data changes.
Progress0 / 4 steps