Complete the code to create a trigger that automatically updates a timestamp column when a row is modified.
CREATE TRIGGER update_timestamp BEFORE UPDATE ON users FOR EACH ROW EXECUTE FUNCTION [1]();The trigger calls the function update_timestamp_function to update the timestamp before any update on the users table.
Complete the code to create a trigger that logs changes after a row is deleted.
CREATE TRIGGER log_delete AFTER DELETE ON orders FOR EACH ROW EXECUTE FUNCTION [1]();The trigger uses log_delete_function to log details after a row is deleted from the orders table.
Fix the error in the trigger creation code by selecting the correct timing keyword.
CREATE TRIGGER check_stock [1] INSERT ON products FOR EACH ROW EXECUTE FUNCTION check_stock_function();The correct timing for this trigger is BEFORE INSERT to check stock before adding a new product.
Fill both blanks to create a trigger that prevents deletion if stock is low.
CREATE TRIGGER prevent_low_stock [1] DELETE ON inventory FOR EACH ROW WHEN (OLD.quantity [2] 5) EXECUTE FUNCTION prevent_delete_function();
The trigger runs BEFORE DELETE and checks if the old quantity is less than or equal to 5 to prevent deletion.
Fill all three blanks to create a trigger that updates a log table after an update on sales.
CREATE TRIGGER [1] [2] UPDATE ON sales FOR EACH ROW EXECUTE FUNCTION [3]();
The trigger named log_sales_update runs AFTER an UPDATE on sales and calls update_sales_log_function to update the log table.