MySQL Forums
Forum List  »  Triggers

Trigger for moving a few records to another table
Posted by: Marek Zima
Date: February 10, 2015 05:13AM

Hi, I have a table message and message_archive and I want to move a few records (500) to message_archive when the count of the records with the same column group_id is the same...

CREATE TRIGGER after_message_update
AFTER INSERT ON message
FOR EACH ROW
BEGIN
DECLARE count_messages integer
DECLARE id_messages integer

SET count_messages = (SELECT COUNT(id) FROM message WHERE message_group_id IN (SELECT id FROM message));
SET id_messages = (SELECT id FROM message WHERE message_group_id IN (SELECT id FROM message));

insert into message_archive
select * from message where count_messages > 2;
delete from message where message_group_id IN id_messages;
END

does somebody help me?

Options: ReplyQuote


Subject
Views
Written By
Posted
Trigger for moving a few records to another table
1661
February 10, 2015 05:13AM


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.