What is the best-practice for maintaining the integrity of linked data entities on update?
My scenario
- I have two entities "Client and Invoice". [client is definition and Invoice is transaction].
- After issuing many invoices to the client it happens that the client information needs to be changed e.g. "his billing address/location changed or business name ... etc".
- It's normal that the users must be able to update the client information to keep the integrity of the data in the system.
- In the invoice "transaction entity" I don't store just the client id but also all the client information related to the invoice like "client name, address, contact", and that's well known approach for storing data in transaction entities.
- If the user created a new invoice the new client information will be stored in the invoice record along with the same client-id (very obvious!).
My Questions
- Is it okay to bind the data entities "clients" from different locations for the Insert and the update? [Explanation: if I followed the approach from step 1-4 I have to bind the client entity from the client table in case of creating new invoice but in case of updating/printing the invoice I have to bind the client entity from the invoice table otherwise the data won't be consistent or integer...So how I can keep the data integrity without creating spaghetti code in the DAL to handle this custom requirements of data binding??]
- I passed through a system that was saving all previous versions of an entity data before the update "keeping history of all versions". If I want to use the same method to avoid the custom binding how I can do this in term of database design "Using MYSQL"? [Explanation: some invoices created with version 1.0 of the client then the client info updated and its version became 1.1 and new invoices created with last version...So is it good to follow this methodology? and how I should design my entities/tables to fulfil the requirements of entity versioning and binding?
- Please provide any book or reference that can kick me in the right direction?
Thanks,