SQL Server add primary key

Posted by Paul on Stack Overflow See other posts from Stack Overflow or by Paul
Published on 2010-05-25T00:07:35Z Indexed on 2010/05/25 0:11 UTC
Read the original article Hit count: 760

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(11)

orders table:
  order_id       int(11)
  ...
  ...
  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.

© Stack Overflow or respective owner

Related posts about sql-server-2005

Related posts about primary-key