Complete the code to create a trigger that runs after an insert on the 'orders' table.
CREATE TRIGGER order_insert_trigger AFTER [1] ON orders FOR EACH ROW EXECUTE FUNCTION notify_order();The trigger should run after an INSERT event on the 'orders' table to automate actions when new orders are added.
Complete the code to define a trigger function that logs the new row's id after insert.
CREATE FUNCTION log_new_order() RETURNS trigger AS $$ BEGIN INSERT INTO order_logs(order_id) VALUES (NEW.[1]); RETURN NEW; END; $$ LANGUAGE plpgsql;The NEW keyword refers to the new row inserted. To log the order, we use its id field.
Fix the error in the trigger creation by completing the missing keyword.
CREATE TRIGGER update_status_trigger BEFORE UPDATE ON orders FOR EACH ROW [1] FUNCTION update_status();The correct keyword to link a trigger to a function is EXECUTE FUNCTION.
Fill both blanks to create a trigger that fires after delete and calls the cleanup function.
CREATE TRIGGER cleanup_trigger AFTER [1] ON sessions FOR EACH ROW [2] FUNCTION cleanup_session();
The trigger should fire after a DELETE event and use the keyword EXECUTE to call the function.
Fill all three blanks to create a trigger that updates the 'updated_at' timestamp before any update on the 'profiles' table.
CREATE TRIGGER update_timestamp BEFORE [1] ON profiles FOR EACH ROW [2] FUNCTION [3]();
The trigger fires BEFORE UPDATE, uses EXECUTE FUNCTION, and calls the function set_updated_at to update the timestamp.
