I’m currently building part of a basic CMS system for the company I work for. There are three main tables…
Companies
Customers
Addresses
Which are all linked to together with foriegn keys. I’ve noticed a glitch when using SQL Server 2005 where if I add a new lead the address maybe updated between the selection of an existing address and the creation of a company causing the company to then have the wrong address associated with it.
My question is… how can I prevent this? Transactions? Timestamp on the address – whereby when the record is selected it gets updated and if the timestamp is different to what the update statement has it inserts a new record?
I’m trying to write a scaleable solution as this is part of the e-commerce website. Users can update their details and much as we can ourselves.
Help.
Thank you.
My suggestion would be to change the data model: adresses are not stand-alone entities that should be referenced, but simply part of the companies’ data.
You could still use a separate table for the adresses, but each company will have its own specific rows in that table, never share the same rows with other companies.