MySQL Forums
Forum List  »  Triggers

Re: Trigger to limit number of rows in another table
Posted by: Peter Brawley
Date: May 26, 2020 11:20AM

Sure ...

declare n smallint;
set n = ( select count(*) from table2 ) - NEW.MaxNumberOfRowsTable2;
if n > 0 then
  insert into table3
    select * from table2 
    order by id limit n;
  delete from table2 
  order by id limit n;
end if;

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Trigger to limit number of rows in another table
17
May 26, 2020 11:20AM


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.