I have a table that needs to be given a new primary key, as my predecesor used a varchar(8) row as the primary key, and we are having problems with it now. I know how to add the primary key, but am not sure of the correct way to add this new primary key to other tables that have the foreign key. Here is what I have:
users table:
old_user_id varchar(8)
...
...
new_user_id int
orders table:
order_id int
...
...
old_user_fk varchar(8)
new_user_fk int(11)
I need to get the same results whether I join the tables on users.old_user_id=orders.old_user_fk or users.new_user_id=orders.new_user_fk. Any help is appreciated.
What is int(11)? SQL Server only has tinyint, smallint, int and bigint
I would suggest you add the new columns to all the tables then update the values so that they match….run a couple of queries to make sure it all works. drop the PK and FK constraints and add new PK and FK constraints using the new columns
of course I would back up all these tables just in case
This way you always have that data in case you need to roll back