Recall & Review
beginner
What is a BEFORE trigger in PostgreSQL?
A BEFORE trigger is a special function that runs automatically before an INSERT, UPDATE, or DELETE operation on a table. It can modify or check data before the change happens.
Click to reveal answer
beginner
When does a BEFORE trigger execute?
It executes just before the data modification statement (INSERT, UPDATE, DELETE) is applied to the table, allowing changes or checks before the data is saved.
Click to reveal answer
intermediate
Can a BEFORE trigger modify the data being inserted or updated?
Yes, a BEFORE trigger can change the data values before they are saved to the table. For example, it can adjust a column value or reject the operation.
Click to reveal answer
intermediate
What happens if a BEFORE trigger raises an exception?
If a BEFORE trigger raises an exception, the data modification is canceled and the error is returned to the user. This can be used to enforce rules or validations.
Click to reveal answer
beginner
How does a BEFORE trigger differ from an AFTER trigger?
A BEFORE trigger runs before the data change happens and can modify or stop it. An AFTER trigger runs after the change is done and cannot modify the data being changed.
Click to reveal answer
When does a BEFORE trigger run in PostgreSQL?
✗ Incorrect
A BEFORE trigger runs before the INSERT, UPDATE, or DELETE operation modifies the table.
Can a BEFORE trigger change the data being inserted?
✗ Incorrect
BEFORE triggers can modify the data before it is saved to the table.
What happens if a BEFORE trigger raises an error?
✗ Incorrect
Raising an error in a BEFORE trigger stops the data modification and returns the error.
Which SQL operations can a BEFORE trigger be attached to?
✗ Incorrect
BEFORE triggers are used with INSERT, UPDATE, and DELETE operations.
How does a BEFORE trigger differ from an AFTER trigger?
✗ Incorrect
BEFORE triggers run before the data change, allowing modification; AFTER triggers run after the change.
Explain what a BEFORE trigger does and when it runs in PostgreSQL.
Think about what happens before saving data to a table.
You got /3 concepts.
Describe how a BEFORE trigger can affect data integrity or validation.
Consider how you might stop bad data from entering your table.
You got /3 concepts.