0
0
SQLquery~10 mins

BEFORE trigger execution in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a BEFORE INSERT trigger that sets the new salary to 5000.

SQL
CREATE TRIGGER set_salary_before_insert BEFORE INSERT ON employees FOR EACH ROW BEGIN SET NEW.salary = [1]; END;
Drag options to blanks, or click blank then click option'
A5000
BNULL
Csalary
DDEFAULT
Attempts:
3 left
💡 Hint
Common Mistakes
Using OLD.salary instead of NEW.salary
Assigning NULL which removes the salary
Using DEFAULT keyword incorrectly
2fill in blank
medium

Complete the code to create a BEFORE UPDATE trigger that prevents salary from being set below 3000.

SQL
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;
Drag options to blanks, or click blank then click option'
A5000
B3000
C1000
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using OLD.salary instead of NEW.salary
Setting salary to a value higher than the minimum
Using incorrect comparison operators
3fill in blank
hard

Fix the error in the BEFORE INSERT trigger that tries to modify OLD values.

SQL
CREATE TRIGGER fix_trigger BEFORE INSERT ON employees FOR EACH ROW BEGIN SET [1].salary = 4000; END;
Drag options to blanks, or click blank then click option'
Asalary
BOLD
Cemployees
DNEW
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to set OLD values in an INSERT trigger
Using table name instead of NEW or OLD
Assigning values directly to column names
4fill in blank
hard

Fill both blanks to create a BEFORE UPDATE trigger that changes the new name to uppercase.

SQL
CREATE TRIGGER uppercase_name_before_update BEFORE UPDATE ON employees FOR EACH ROW BEGIN SET NEW.name = [1](NEW.name); END;
Drag options to blanks, or click blank then click option'
ATRIM
BLOWER
CUPPER
DLENGTH
Attempts:
3 left
💡 Hint
Common Mistakes
Using LOWER instead of UPPER
Using LENGTH which returns a number
Using TRIM which removes spaces
5fill in blank
hard

Fill all three blanks to create a BEFORE INSERT trigger that sets new salary to 6000 if NULL or less than 6000.

SQL
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;
Drag options to blanks, or click blank then click option'
ANULL
B<
C6000
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using IS NOT NULL instead of IS NULL
Using > instead of < for comparison
Comparing to wrong salary value