MySQL Forums
Forum List  »  Triggers

Re: Trigger to limit number of rows in another table
Posted by: Davor Geci
Date: May 26, 2020 12:57PM

This is my end result, but it doesn't do anything. There is obviusly an error:

BEGIN
declare n int;
SET n=0;
IF NEW.maxnumkeys > 0 THEN
set n = ( select count(*) from wpre_vbat_ai_keys WHERE userid = NEW.userid) - NEW.maxnumkeys;
ELSE
SET n=0;
END IF;

if n > 0 then
insert into wpre_vbat_ai_keys_archive
select * from wpre_vbat_ai_keys
WHERE userid = NEW.userid
order by id limit n;
delete from wpre_vbat_ai_keys
WHERE userid = NEW.userid
order by id limit n;
end if;
END

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Trigger to limit number of rows in another table
29
May 26, 2020 12:57PM


Sorry, only registered users may post in this forum.

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.