Complete the code to create a trigger that runs before an insert on the 'orders' table.
CREATE TRIGGER before_order_insert [1] INSERT ON orders FOR EACH ROW BEGIN END;The trigger must be defined as BEFORE INSERT to run before inserting a row.
Complete the code to reference the new row's 'quantity' value inside the trigger.
SET @new_quantity = NEW.[1];Inside triggers, NEW.column_name refers to the new row's column. Here, 'quantity' is the correct column name.
Fix the error in the trigger definition by choosing the correct timing keyword.
CREATE TRIGGER update_stock [1] UPDATE ON products FOR EACH ROW BEGIN END;BEFORE UPDATE triggers run before the update happens, allowing changes to NEW values.
Fill both blanks to create a trigger that prevents deleting from 'users' table.
CREATE TRIGGER prevent_user_delete [1] [2] ON users FOR EACH ROW BEGIN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Delete not allowed'; END;
To prevent deletion, use a BEFORE DELETE trigger that raises an error.
Fill all three blanks to create a trigger that logs inserts with timestamp and user ID.
CREATE TRIGGER log_insert [1] INSERT ON orders FOR EACH ROW BEGIN INSERT INTO audit_log (action, user_id, action_time) VALUES ([2], NEW.user_id, [3]); END;
The trigger runs AFTER INSERT to log the action. The action is the string 'INSERT' and the current time is NOW().