0

I am having an issue figuring out a solution to not lose old information.

For example, customers can place many orders. Let's a customer, Mary, makes her 1st order in 2013. Fast-forward to 2014, Mary updates her address and makes a new order. This 2nd order will reflect the new changes, but the 1st order will also. How can I keep the old customer information for the 1st order? Should I create a new customer record whenever a customer updates their information?

Customers

+-----+--------+--------+-------------------+-----------+----------+
| id  | fname  | lname  | address           | last_updated         |
+-----+--------+--------+-------------------+----------------------+
| 1   | mary   | jane   | 123 some st.      | 2014-07-10 01:20:00  |
+-----+--------+--------+-------------------+----------------------+

Orders

+----+-------------+---------------------+---------------------+
| id | customer_id | order_date          | delivery_date       |
+----+-------------+---------------------+---------------------+
| 1  | 1           | 2013-04-01 13:00:00 | 2013-04-01 16:00:00 |
| 2  | 1           | 2014-07-10 01:30:00 | 2014-07-10 02:00:00 |
+----+-------------+---------------------+---------------------+

2 Answers2

0

You create an extra table with customer ID and all other fields that will possibly change over the time.

In the orders table, you link to the id of this new table, not to the costumers tables.

customers(customer_id, first_name, last_name...)
customer_info(id, customer_id, address, other field)
orders(id, customer_info_id, order_date, ...etc)
Jehad Keriaki
  • 3,127
  • 1
  • 16
  • 17
0

And this is why you shouldn't use such a simple pattern :)

Please see Ready-to-Use Database models example (s) for a list of references.

An address should be its own entity.

People -< PeopleAddresses >- Addresses

The Sales Order points to the Address (as the Billing Address), and the Sales Order Line Items point to the Address (as the ShipTo Address). Not the person.

Don't let people delete or modify addresses. They can request corrections.

Neil McGuigan
  • 8,653
  • 5
  • 42
  • 57