Triggers: counting rows in a bridge table after INSERT
1
vote
1
answer
853
views
I'm using a trigger in order to make a Statistic Table. I have this many-to-many relationship where I have an
Order
that can have multiple Product
's and viceversa. So after an INSERT on Order
, using JPA, new rows are automatically inserted in the bridge table Order_Products
.
When in the Trigger I use
SET @numOfOPs = (
SELECT COUNT(IDOrder)
FROM Order_Product
WHERE IDOrder = NEW.ID)
on new entries, the count on Order_Procut seems to return 0 (or the value before the insert on Order).
Here the signature of the Trigger:
CREATE TRIGGER Order_AFTER_INSERT
AFTER INSERT ON Order
FOR EACH ROW
What could be the problem? I will add additional information if needed.
Asked by Filippo Scaramuzza
(11 rep)
Feb 12, 2022, 05:04 PM
Last activity: May 31, 2025, 08:03 AM
Last activity: May 31, 2025, 08:03 AM