0
0
PostgreSQLquery~5 mins

Trigger function creation in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a trigger function in PostgreSQL?
A trigger function is a special function that automatically runs when a specified event happens on a table, like inserting, updating, or deleting data.
Click to reveal answer
beginner
Which language is commonly used to write trigger functions in PostgreSQL?
PL/pgSQL is the most common language used to write trigger functions in PostgreSQL because it allows procedural logic inside the database.
Click to reveal answer
beginner
What keyword is used to create a trigger function in PostgreSQL?
The keyword used is CREATE FUNCTION, followed by the function name and the trigger return type.
Click to reveal answer
intermediate
What must a trigger function return in PostgreSQL?
A trigger function must return a special type called TRIGGER to work properly with triggers.
Click to reveal answer
intermediate
How do you access the row data inside a trigger function during an INSERT event?
You use the special variable NEW to access the new row data being inserted.
Click to reveal answer
Which statement correctly starts a trigger function in PostgreSQL?
ACREATE FUNCTION my_trigger() RETURNS TRIGGER AS $$ BEGIN ... END; $$ LANGUAGE plpgsql;
BCREATE TRIGGER my_trigger() BEGIN ... END;
CCREATE PROCEDURE my_trigger() RETURNS VOID AS $$ ... $$;
DCREATE FUNCTION my_trigger() RETURNS VOID AS $$ ... $$;
What does the NEW keyword represent inside a trigger function?
AThe old row before update or delete
BThe new row being inserted or updated
CThe table name
DThe trigger event type
Which event can a trigger function respond to?
AINSERT
BUPDATE
CDELETE
DAll of the above
What language must be specified when creating a trigger function in PostgreSQL?
ASQL
BPython
Cplpgsql
DJavaScript
What is the return type of a trigger function?
ATRIGGER
BINTEGER
CVOID
DBOOLEAN
Explain how to create a basic trigger function in PostgreSQL that logs inserts on a table.
Think about the function structure and what it should return.
You got /6 concepts.
    Describe the role of trigger functions and how they interact with database events.
    Consider what happens when data changes in a table.
    You got /5 concepts.