Reputation: 257
If I have a table called group:
[Part_one_id|Part_two_id|Part_three_id|status|location]
1 7 6 ready long/lat
2 2 9 in-use long/lat
And there are three separate part tables for each part:
Part one Part two Part three
[id][measurement] [id][pressure] [id][temperature]
Which way should I track location and status?
Upvotes: 1
Views: 490
Reputation: 1898
There are a few big issues I see with your table structure off the bat.
As far as the answer to the question itself. I don't particularly like MySQL triggers because the syntax isn't that great and they don't do as much as they do in other databases like PostgreSQL or Oracle. That being said, the appealing thing about triggers in this instance would be that the trigger would execute in the same transaction as the update/insert that triggers it, so you would get that business rule for free. However, depending on what you use to access your database you can just start a transaction and not end it until you've done your auditing inserts.
Ultimately what your tables would change to look like would be:
group: id, name, created, modified, status
part_group: part_id, group_id, created, modified
location: id, lat, long
group_location: group_id, location_id, created, modified
Then the most recently created group_location would point to your current location for a given group.
Upvotes: 1