I'm designing a table structure that at times columns need to revert to their "original" values.
This is for a customer table that is assigned to a company, once assigned to a company the values change to that of the companies values, and when the association is removed they need to revert back.
Here is part of the table structure
For a mass update reverting customers back to their original (like when a company is removed from the database) I'm thinking of a query like:
I ran it and it seemed to work just fine, but I wanted to verify that the query wouldn't cause any problems in and of itself.
I am assuming that it will work fine, but if I had the order of operations set up differently (such as setting origcontractid to null before setting the contractid to the origcontractid) then I could end up with problems (such as two nulls when only the original should turn null).
Am I correct in my thinking?
Thanks.
This is for a customer table that is assigned to a company, once assigned to a company the values change to that of the companies values, and when the association is removed they need to revert back.
Here is part of the table structure
Code:
Table: customer
customerid (PK, bigint, not null)
contractid (int, not null)
origcontractid (int, null)
salesrepid (int, null)
origsalesrepid (int, null)
companyid (int, null)
Code:
UPDATE customer SET contractid = origcontractid, origcontractid = NULL, salesrepid = origsalesrepid, origsalesrepid = NULL, companyid = NULL WHERE companyid = 2
I am assuming that it will work fine, but if I had the order of operations set up differently (such as setting origcontractid to null before setting the contractid to the origcontractid) then I could end up with problems (such as two nulls when only the original should turn null).
Am I correct in my thinking?
Thanks.