bcooler
Programmer
- Jun 13, 2009
- 132
OK, I have a general strategy question.
I am used to creating records that store related tables' primary keys. For example, when I put a customer name in an order form, I store their key, not the name (243, not John Smith). I believe this is the standard way to store info. It allows me to have access to all of John Smith's data, not just a name (and many other reasons).
However, my brother wants me to make a database for him and I am concerned with using the above method is all instances. For example, if a particular customer has a discount associated with their account (% stored in the customer table), I can make an order form that takes the existing percentage and apply it to the order (everything is good at this point).
Now, here's the problem. Let's say next month this same customer has their discount adjusted in the customer table (in an attempt to give a better price on future sales). New orders will still work just as before, but older completed orders will now seem to have the current discount % instead of the historical discount given at time of sale (due to storing the customer's autonumber and extracting the associated discount; a big problem).
I can have the Order table store the actual discount value in the record instead of only storing the customer primary key (and looking up the discount). This will store the actual discount for all time in this record.
MY QUESTION:
I've always been told to store primary keys and do not store redundant information. However, this solution I described seems to disregard that strategy (discount code is now in the customer table AND the order table). I don't know what hidden "grenades" I'm about to get myself into if I go forward with the above solution.
Anyone willing to hold my hand?
I am used to creating records that store related tables' primary keys. For example, when I put a customer name in an order form, I store their key, not the name (243, not John Smith). I believe this is the standard way to store info. It allows me to have access to all of John Smith's data, not just a name (and many other reasons).
However, my brother wants me to make a database for him and I am concerned with using the above method is all instances. For example, if a particular customer has a discount associated with their account (% stored in the customer table), I can make an order form that takes the existing percentage and apply it to the order (everything is good at this point).
Now, here's the problem. Let's say next month this same customer has their discount adjusted in the customer table (in an attempt to give a better price on future sales). New orders will still work just as before, but older completed orders will now seem to have the current discount % instead of the historical discount given at time of sale (due to storing the customer's autonumber and extracting the associated discount; a big problem).
I can have the Order table store the actual discount value in the record instead of only storing the customer primary key (and looking up the discount). This will store the actual discount for all time in this record.
MY QUESTION:
I've always been told to store primary keys and do not store redundant information. However, this solution I described seems to disregard that strategy (discount code is now in the customer table AND the order table). I don't know what hidden "grenades" I'm about to get myself into if I go forward with the above solution.
Anyone willing to hold my hand?