MySQL Forums
Forum List  »  Triggers

Re: Setting a row's value to the primary key after insert
Posted by: Carl Dunham
Date: May 29, 2006 09:17PM

Oh, jeez, I missed that part. Yes, you are caught on the horns of a dilemna. You can only update NEW in a BEFORE, and you don't have the autoincrement id until AFTER.

So you want to do this a bit differently:

delimiter //
CREATE TRIGGER calendar_insert_after AFTER INSERT
ON calendar
FOR EACH ROW
BEGIN
IF NEW.group_id IS NULL THEN
UPDATE calendar SET group_id = NEW.calendar_id WHERE calendar_id = NEW.calendar_id;
END IF
END; //
delimiter ;

Basically, you have to issue a new query to do it.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Setting a row's value to the primary key after insert
2056
May 29, 2006 09:17PM


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.