i have 2 tables:
Codes table with following column:
Name, Code
History table with following column:
Name, BU, Plan.
Now, I want code column of Codes table in place of Name column of History table.
I.e History table should contain Code, BU, Plan.
Here how can i achieve this?
Best Answer
Assuming
Code
is aVARCHAR(32)
(just change the first line if my assumption is incorrect):If you absolutely need the columns to be in the same order (you shouldn't), you can rebuild the table as follows:
In order to prevent user activity from affecting or being affected, you'll want to do this during a maintenance window, or surround the above with a serializable transaction.
When you're happy that the change is successful, you can drop the old copy: