Maintaining relationship and history in mysql databases -


i designing mysql database , have come across these relations grow in future.

suppose customer tied 2 different tables policies , options.

each customer has multiple relationship policies , likewise options. since keeping details , history of table every time add relation customer, have maintain 2 tables. calculate price customer owes, have go thru customer_policies customer_options , calculate total price. number of tables increases relationship increases.

  • if customer has relation policies have 2 tables - customer_policies , customer_policies_details.
  • if customer has 1 more relation options, add 3 more - customer_options, , customer_option_history.
  • like wise, keep on adding 2 more tables if there 1 more relation , problem grows , grows.

i have tried 2 different options have mentioned below. wanted know best way solve problem table can maintained relation grows.

option 1:

customer_policies:

customerpolicyid customerid policyid status 1                1          1        active  2                1          2        active 

customer_policies_details:

customerpolicydetailsid customerpolicyid price 1                       1                10    2                       2                20 

customer_options:

customeroptionid customerid optionid status 1                1          1        active  2                1          2        active 

customer_options_details:

customeroptiondetailsid customeroptionid price 1                       1                10    2                       2                20     

option 2:

create single table customer_selections , use type , id field instead so:

customer_selections:

customerselctionid  customerid  type    id status 1                   1           policy  1  active 2                   1           policy  2  active 3                   1           option  1  active 4                   1           option  2  active 

customer_selection_details:

detailsid  customerselctionid  price    1           1                  10   2           2                  20   3           3                  10   4           4                  20   

to create history of have create customer_selections_details , keep track of changes.

there should better ways solve problem.


Comments