Recall & Review
beginner
What is an INSTEAD OF trigger in PostgreSQL?
An INSTEAD OF trigger is a special trigger on a view that runs instead of the usual action (like INSERT, UPDATE, DELETE) on the view. It lets you define how to handle changes on views that normally can't be directly modified.
Click to reveal answer
beginner
Why do we need INSTEAD OF triggers for views?
Views often combine data from multiple tables and cannot be directly changed. INSTEAD OF triggers let us write code to update the underlying tables when someone tries to change the view.Click to reveal answer
intermediate
How do you create an INSTEAD OF trigger for a view in PostgreSQL?
You first create a function that defines what happens on INSERT, UPDATE, or DELETE on the view. Then you create the trigger on the view using CREATE TRIGGER ... INSTEAD OF ... ON view_name FOR EACH ROW EXECUTE FUNCTION your_function();Click to reveal answer
beginner
Can you directly insert data into a view without an INSTEAD OF trigger?
No, normally you cannot insert, update, or delete data directly in a view if it involves multiple tables or complex queries. INSTEAD OF triggers provide a way to handle these operations safely.
Click to reveal answer
intermediate
What happens if an INSTEAD OF trigger is defined on a view and you perform an UPDATE on that view?
The INSTEAD OF trigger function runs instead of the normal UPDATE. This function can update the underlying tables as needed to reflect the change.
Click to reveal answer
What does an INSTEAD OF trigger do on a view?
✗ Incorrect
INSTEAD OF triggers run a function instead of the usual INSERT, UPDATE, or DELETE on a view.
Why can't you normally update a view that combines multiple tables?
✗ Incorrect
Views do not store data themselves; they show data from underlying tables, so direct updates are not allowed without special handling.
Which SQL command is used to create an INSTEAD OF trigger on a view?
✗ Incorrect
You use CREATE TRIGGER with the INSTEAD OF clause on the view to define the trigger.
What must you define to use an INSTEAD OF trigger?
✗ Incorrect
An INSTEAD OF trigger requires a trigger function that defines what happens when the trigger fires.
If you want to allow INSERTs on a view, what should you do?
✗ Incorrect
To allow INSERTs on a view, you create an INSTEAD OF INSERT trigger that handles inserting data into underlying tables.
Explain what an INSTEAD OF trigger is and why it is useful for views.
Think about how views show data but don't store it.
You got /4 concepts.
Describe the steps to create an INSTEAD OF trigger for a view in PostgreSQL.
Remember you need both a function and a trigger.
You got /4 concepts.