Using SQL Server Management Studio (SSMS), you can use its table designer to determine the final state of the table. Before saving the changes, create a script change and save the script. Cancel the design window, open the script and view it. SSMS may already have generated a script that does everything you need, fixing the primary-foreign key relationship while saving all existing data. If not, you will have a script already running that does most of what you need to do, and should be able to modify it for your needs.
source share