![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a database design problem which I'd like a few pointers on, please. I need to store a data point - it's the cost of something for a given client. This cost will normally remain static, but on occasion it might change. I'm thinking a few changes per year, no more. Updating a value as required in the client's record is easy, but I need to be able to find out what the value was on a given day. In other words I need to be able to store the history of changes to this value, and to be able to query the value from that history. In my inexperience, the first (and only simple) design I've come up with is something like: client_id int cost int date_changed date and adding a record to that table when the cost changes. I can then query the table for the given client, ordered by date_changed descending, where the date_changed is less than (i.e. before) the given date, and take the top row from the result. Is this a reasonable way to solve the problem? I'm sure others must have solved similar problems in the past - is there a 'standard' solution? |
#3
| |||
| |||
|
|
Is this a reasonable way to solve the problem? I'm sure others must have solved similar problems in the past - is there a 'standard' solution? sounds like an excellent solution to me |
)
#4
| |||
| |||
|
|
strawberry wrote: Is this a reasonable way to solve the problem? I'm sure others must have solved similar problems in the past - is there a 'standard' solution? sounds like an excellent solution to me If you knew how inexperienced I am with DB design, you'd understand why I'm so chuffed to hear you say that. )But I'm still open to better ideas if there are any... |
#5
| |||
| |||
|
|
I need to store a data point - it's the cost of something for a given client. This cost will normally remain static, but on occasion it might change. I'm thinking a few changes per year, no more. Updating a value as required in the client's record is easy, but I need to be able to find out what the value was on a given day. In other words I need to be able to store the history of changes to this value, and to be able to query the value from that history. In my inexperience, the first (and only simple) design I've come up with is something like: client_id int cost int date_changed date and adding a record to that table when the cost changes. I can then query the table for the given client, ordered by date_changed descending, where the date_changed is less than (i.e. before) the given date, and take the top row from the result. |
#6
| |||
| |||
|
|
The other possibility is using the "slowly changing dimensions" model from data warehousing theory. This is a more complex design model and may not be warranted given the size/scope of your data. snip |
#7
| |||
| |||
|
|
It's a good one. The only POSSIBLE improvement is one that would require some application code (or a trigger, perhaps) to maintain and that would be to add an "active" flag on the record to make finding current prices much faster than a huge collection of MAX() functions to find the most recent date. |
)![]() |
| Thread Tools | |
| Display Modes | |
| |