Complete the code to create a BEFORE UPDATE trigger that sets the new value of a column.
CREATE TRIGGER update_salary BEFORE UPDATE ON employees FOR EACH ROW SET NEW.salary = NEW.salary [1] 1000;
The trigger adds 1000 to the new salary before updating the row.
Complete the code to prevent updating the salary if the new salary is less than the old salary.
CREATE TRIGGER check_salary BEFORE UPDATE ON employees FOR EACH ROW BEGIN IF NEW.salary [1] OLD.salary THEN SET NEW.salary = OLD.salary; END IF; END;The trigger checks if the new salary is less than the old salary and resets it to the old salary to prevent decrease.
Fix the error in the trigger code to correctly assign a new value to a column in a BEFORE UPDATE trigger.
CREATE TRIGGER update_bonus BEFORE UPDATE ON employees FOR EACH ROW SET [1].bonus = NEW.bonus + 500;
In BEFORE UPDATE triggers, you assign new values using the NEW keyword, not OLD or table names.
Fill both blanks to create a BEFORE UPDATE trigger that prevents the 'status' column from being changed to 'inactive'.
CREATE TRIGGER prevent_inactive BEFORE UPDATE ON users FOR EACH ROW BEGIN IF NEW.status [1] 'inactive' THEN SET NEW.status = [2].status; END IF; END;
The trigger checks if the new status is 'inactive' and resets it to the old status to prevent the change.
Fill all three blanks to create a BEFORE UPDATE trigger that increases 'points' by 10 only if the new 'level' is greater than the old 'level'.
CREATE TRIGGER level_up BEFORE UPDATE ON players FOR EACH ROW BEGIN IF NEW.level [1] OLD.level THEN SET NEW.points = NEW.points [2] [3]; END IF; END;
The trigger checks if the new level is greater than the old level, then adds 10 points to the new points value.