COMP3311 Final Exam 20T3 |
The University of New South Wales COMP3311 Database Systems Final Exam 20T3 |
Database Systems |
Note: This question is asking you to write some PLpgSQL functions. While you have a PostgreSQL server and could test these out, we do not expect you to do this. Simply write the code in the file q9.txt as accurately as you can. Your work will not be tested via PostgreSQL, but will be assessed based on how close your code is to a correct solution.
For this question, assume that the MemberOf table has two extra fields: joined (date the performer joined the group), departed (date the performer left the group).
Exercises:
Write triggers to ensure that the Groups data is correctly maintained when the following changes occur:
When the last member of a group leaves (i.e. all members are noted as departed)
When a group changes its name
For each case, you must write a suitable PostgreSQL CREATE TRIGGER statement and define a PLpgSQL function (or collection of functions) to carry out the appropriate actions. You must specify whether the trigger is executed before or after after the modification event. Your triggers should be defined so as to avoid trigger-cycles; to do this, you are allowed to assume that PostgreSQL allows triggers to be restricted to updates of specified columns.
Instructions: