I want to create a trigger on my 'persons' table so that after an update, if the attribute clubid is changed, attribute clubname should be changed.
I have a rough syntax below, which I think should work, but I'm not sure how to limit it updates where the clubid has changed.
Can anyone tell me how to limit it to running if the value clubid has changed, and also whether the syntax below is otherwise OK?
(I know this will fail as is, because the 'lastvisit' attribute in the person record is updated as soon as the visitor arrives on the site and I get "Can't update table 'persons' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.")
CREATE TRIGGER tr_UpdateClubName
AFTER UPDATE ON persons FOR EACH ROW
SET clubname = (
SELECT clubname FROM clubs WHERE persons.clubid = clubs.clubno