I've come across a slight issue when designing a trigger statement in our MySQL DB today:
We have the following relevant tables:
- quote (quote_key, date, discount_rate, discount_period, supplier_key)
- part (part_key, part_name, ...)
- part_quote (pq_key, part_price, fk_quote_key, fk_part_key)
- part_approval (papproval_key, is_approved, fk_part_quote_key)
Now for an explanation of the logic:
Every supplier issues quotes for different inputs into a manufacturing process (e.g. parts and components). If the price for a part is about right, they will be approved for manufacturing and can thus be used by our engineers. Since we want to be able to receive quotes from different suppliers for the same parts to enable a comparison, I've tried to model this process by using the part_quote and part_approval table.
On to my problem: If I want to approve a new part_quote, I would like the BOOL flag "is_approved" in all (or the most recent) old quotes to be automatically set to FALSE.
I tried to get this done by issuing a trigger statement: CREATE TRIGGER update_approval BEFORE INSERT ON part_approval FOR EACH ROW --- ??
I have some problems selecting the right rows to update:
- How do I select the part_key, which will ultimately identify all relevant rows that require updating?
- How do I select only the old (or most recent) rows?
I would have loved to include a screener but unfortunately, I do not have 10reps yet :/
Thank you so much in advance, All the best, Marius