After spending some time thinking about all that was said about archival accuracy between customer, work order and service item tables, I've come up with a design plan that's a combination of rocknbil & Dijkgraaf ideas.
I'd like your opinion on my idea...
The customer data that has the potential to change is the:
. address
. phone number
. email address
. alternate contact info
So...
Creating the customer table and address tables. 1. The customer table always contains just the customers' current:
. customerID
. addressID (the pointer to the customers' current address in the address table)
. first name
. last name
. statusID
. Notes
2. The address table stores current and past address info:
. addressID
. customerID
. street
. city
. stateID
. zipcode
. phone number
. email address
. alternate contact info
The customer table always contains and/or points to current customer data.
When a new work order record is created, the customers' customerID and addressID from the customer table is included.
The addressID stored in a customer table record should always point the the last address table record inserted for that customerID – the current address.
The addressID stored in a work order table record should always point the last address table record inserted for that customerID at the time the work order record was created – a current or past address.
If a new customer is added or an existing customer has an address change and there are no open work orders for that customer, a new address record for that customerID is inserted into the address table and the addressID in the customer table record is updated.
If an existing customer has an address change and there is an open work order for that customer, the existing address record for that customerID is updated in the address table and the addressID in the customer table record is not updated.
There would be no need to search for or calculate the current customer address because it's always pointed to by the addressID in the customer table.
Creating the items table. The work order service items table would simply have records for that workorderID (as rocknbil had said) containing the actual values relating to all service items purchased under that work order at the time the work order was created.
1. The items table would include the actual:
. itemID
. item name
. unit price
. quantity
The price list table always contains and/or points to current item and pricing data.
When item records are created for a work order, the workorderID and the actual values from the current price list table are included in each item record for that work order.
If a new item needs to be added to an existing work order and the work order is open, a new item record for that workorderID is inserted into the items table using the actual values from the current price list table.
If an existing item needs to be updated for an existing work order and the work order is open, a item record for that workorderID is updated. The current price list table is not used.
If an existing item needs to be replaced with new item for an existing work order and the work order is open, a item record for that workorderID is updated using the actual values from the current price list table.
Closed work orders and their associated data can not be altered. I think this design insures archival integrity for open and closed work orders.
What do you all think of my design?