Another option is to create a new table with the corresponding primary key. Script to display any relationship except the basic structure of the table in the table. Set the database to single-user mode (so that no one can modify the records during the transfer process) after you have the current backup.
Then insert the records from the old table into the baths, say 10,000 at a time. This will take longer than a single set-based insert, but a timeout will be much less likely. You may need to experiment to find the optimal batch size. Once you're done, drop the old table, rename the new table, and set up any pk / fk relationship. Then exit single-user mode.
This is a task that should be performed only during production after hours and as a task of servicing the database, no one else should have access to the database during its occurrence.
Please note that you may not have unique information about the natural key of the table. In this case, you may have a problem if you use it as pk and you may need to move some entries to the exception table to fix it. Even if you use the surogate key as a new PC, I highly recommend a unique index on the natural key of the table, if at all possible.
Hlgem source share