Complete the code to create a BEFORE INSERT trigger that sets the new salary to 5000.
CREATE TRIGGER set_salary_before_insert BEFORE INSERT ON employees FOR EACH ROW BEGIN SET NEW.salary = [1]; END;The trigger sets the NEW.salary value to 5000 before inserting the row.
Complete the code to create a BEFORE UPDATE trigger that prevents salary from being set below 3000.
CREATE TRIGGER check_salary_before_update BEFORE UPDATE ON employees FOR EACH ROW BEGIN IF NEW.salary < [1] THEN SET NEW.salary = [2]; END IF; END;
The trigger checks if the new salary is less than 3000 and sets it to 3000 if true.
Fix the error in the BEFORE INSERT trigger that tries to modify OLD values.
CREATE TRIGGER fix_trigger BEFORE INSERT ON employees FOR EACH ROW BEGIN SET [1].salary = 4000; END;
In a BEFORE INSERT trigger, only NEW can be modified. OLD is not available.
Fill both blanks to create a BEFORE UPDATE trigger that changes the new name to uppercase.
CREATE TRIGGER uppercase_name_before_update BEFORE UPDATE ON employees FOR EACH ROW BEGIN SET NEW.name = [1](NEW.name); END;The UPPER function converts the new name to uppercase before update.
Fill all three blanks to create a BEFORE INSERT trigger that sets new salary to 6000 if NULL or less than 6000.
CREATE TRIGGER set_min_salary_before_insert BEFORE INSERT ON employees FOR EACH ROW BEGIN IF NEW.salary IS [1] OR NEW.salary [2] [3] THEN SET NEW.salary = 6000; END IF; END;
The trigger checks if NEW.salary is NULL or less than 6000, then sets it to 6000.