Create a DELETE Trigger to Log Removed Records
📖 Scenario: You manage a small library database. When a book record is deleted, you want to keep a log of the deleted book's title and deletion time for future reference.
🎯 Goal: Build a DELETE trigger that automatically saves the title of the deleted book and the time it was deleted into a separate log table.
📋 What You'll Learn
Create a table called
books with columns id (integer primary key) and title (text).Create a table called
deleted_books_log with columns book_title (text) and deleted_at (timestamp).Create a DELETE trigger on the
books table.The trigger should insert the deleted book's title and current timestamp into
deleted_books_log.💡 Why This Matters
🌍 Real World
Logging deleted records helps keep track of important data changes and supports auditing in real-world databases.
💼 Career
Database administrators and developers often use triggers to automate tasks like logging, enforcing rules, and maintaining data integrity.
Progress0 / 4 steps