MySQL Forums
Forum List  »  Triggers

Trigger to limit number of rows in another table
Posted by: Davor Geci
Date: May 26, 2020 07:53AM

Can you help me with 2 triggers on 2 tables?
I have Table1 that is having fields:
ID
MaxNumberOfRowsTable2
UserID

Table2 with fields:
ID
Name
UserID

I need to create a trigger on Table1 that will fire every time I change a field MaxNumberOfRowsTable2 and delete all extra rows in Table2 ordered by ID.

For example if Table2 is having 100 rows and we change the MaxNumberOfRowsTable2 field in Table1 to value 15, the trigger should delete all the rows in Table2 and only leave the 15 oldest records.
Can anyone help me with this trigger?

Thanks,
Davor

Options: ReplyQuote


Subject
Views
Written By
Posted
Trigger to limit number of rows in another table
941
May 26, 2020 07:53AM


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.