0
0
PostgreSQLquery~5 mins

BEFORE trigger behavior in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AAfter the data modification statement executes
BBefore the data modification statement executes
COnly during SELECT queries
DOnly when the database starts
Can a BEFORE trigger change the data being inserted?
AYes, it can modify the data before saving
BOnly after the data is saved
COnly if the data is numeric
DNo, it can only read data
What happens if a BEFORE trigger raises an error?
AThe data change proceeds anyway
BThe error is ignored
CThe database restarts
DThe data change is canceled
Which SQL operations can a BEFORE trigger be attached to?
AINSERT, UPDATE, DELETE
BSELECT only
CCREATE and DROP
DALTER only
How does a BEFORE trigger differ from an AFTER trigger?
ABoth run at the same time
BBEFORE triggers run after data changes; AFTER triggers run before
CBEFORE triggers run before data changes; AFTER triggers run after
DBEFORE triggers only run on SELECT
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.