Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a row-level trigger that fires for each row inserted.
PostgreSQL
CREATE TRIGGER trg_example
AFTER INSERT ON employees
FOR EACH [1]
EXECUTE FUNCTION log_employee_insert(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using FOR EACH STATEMENT instead of FOR EACH ROW for row-level triggers.
✗ Incorrect
The FOR EACH ROW clause makes the trigger fire once for every row affected.
2fill in blank
mediumComplete the code to create a statement-level trigger that fires once per statement.
PostgreSQL
CREATE TRIGGER trg_example
BEFORE UPDATE ON orders
FOR EACH [1]
EXECUTE FUNCTION check_order_status(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing row-level and statement-level triggers.
✗ Incorrect
The FOR EACH STATEMENT clause makes the trigger fire once per SQL statement.
3fill in blank
hardFix the error in the trigger creation by choosing the correct timing keyword.
PostgreSQL
CREATE TRIGGER trg_update
[1] UPDATE ON products
FOR EACH ROW
EXECUTE FUNCTION update_timestamp(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid timing keywords like DURING.
✗ Incorrect
Triggers must use BEFORE or AFTER to specify timing. DURING is invalid.
4fill in blank
hardFill both blanks to create a trigger that fires once per statement before delete.
PostgreSQL
CREATE TRIGGER trg_cleanup [1] DELETE ON sessions FOR EACH [2] EXECUTE FUNCTION cleanup_sessions();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing row-level and statement-level keywords.
✗ Incorrect
The trigger fires BEFORE the delete statement and once per STATEMENT.
5fill in blank
hardFill all three blanks to create a row-level trigger that fires after insert.
PostgreSQL
CREATE TRIGGER trg_audit [1] [2] ON employees FOR EACH [3] EXECUTE FUNCTION audit_changes();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using BEFORE instead of AFTER.
Confusing event types or trigger levels.
✗ Incorrect
The trigger fires AFTER INSERT on each ROW.