I’ve got a table:
CA
- ca_id
- placement_id
- blah
- blah
This table gets updated with new unique placements every hour from data warehouse. Now the end-user wants to track statuses for those placements.
I was thinking of adding a new table which would get updated hourly as well:
CA_Status
- placement_id
- record_status
- last_updated_on
OPTION 1:
Add unique constraint to placement_id. Implement some mechanism (trigger perhaps?) where if the placement exists update the record_status and last_updated_on fields. If not create a new record. I can then join this with the CA table, by placement_id, and get the latest status of each placement.
OPTION 2
I can dump the unique constraint on the placement_id. This will let the table grow with the latest record_status for any placement. When I join I can get MAX(last_updated_on) to get the latest record_status.
OPTION 3:
Dump the CA_Status table all together. Add the new attributes to the CA table and do something like option 1
If OPTION 1 are triggers the way to go?
If OPTION 2 would this make my table un-necessarily large.
update: I guess with Option 1 I don’t really need the CA_Status table. I could possibly incorporate those fields into the CA table and update accordingly.
Since you have full control over the process, OPTION 3 seems easiest to me.
record_status and last_updated_on into the CA table, and include these fields in your INSERT statement.
If your requirement is to change the record_status and last_updated_on every time a change is made to the CA table, then an on UPDATE trigger could be used.
However, you say you have full control over the business logic layer. So, changing the UPDATE statements to update those fields as well is again, the easiest way.
Unless, you need to track the hourly change in status over time. Then a separate table is required to hold those changes.