MySQL Forums
Forum List  »  Triggers

Help for newbie to triggers
Posted by: Greg Johll
Date: September 26, 2005 08:44PM

I'm a newbie when it comes to triggers so here's what I'm trying to accomoplish:

If column deletedFlag changes in tblPerson I want to either insert a row if deletedFlag changes to 0, or delete one or more rows if deletedFlag changes to 1, and these rows would be inserted/deleted from tblPersonGroup.

So here's somewhat of an attempt, mixing in some pseudo code when I don't know what I'm doing.

------------------------------------------------------

Delimiter //

CREATE TRIGGER updateGroups AFTER UPDATE ON tblPerson
FOR EACH ROW BEGIN
if (tblPerson.deletedFlag == 1){
DELETE FROM tblPersonGroup
WHERE personID = personIDofThisRow
}

if (tblPerson.deletedFlag == 2){
INSERT INTO tblPersonGroup(personID,groupID)
VALUES(personIDofThisRow,2)
}
END
//

-----------------------------------------------------

Any assistance out there is greatly appreciated....now I'm back to RTFM.

Options: ReplyQuote


Subject
Views
Written By
Posted
Help for newbie to triggers
2909
September 26, 2005 08:44PM
2015
September 26, 2005 08:49PM
2110
September 27, 2005 06:08PM
1688
September 27, 2005 06:33PM
2010
September 27, 2005 07:55PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.