Adding PRIMARY KEY and IDENTITY attributes to SQL Server 2008 tables
The easiest way to do this is to use the SSMS GUI, right click the designer and use "Generate Scripts". That generates you a table rebuild that preserves data and makes the schema changes for you.

If you care about performance you need to use the SWITCH technique. Make the schema of the two tables compatible with switch, then switch, then alter the schema back. That way you can add the IDENTITY property without (or with reduced) data movement.


  SWITCH from a table with no PK to a table with a PK


Yes, that doesn't work. Create a compatible table for use with switch. You can switch heaps just fine, but both sides need to be heaps.



You can write the rebuild script yourself.


Create a table that has the desired schema
IDENTITY_INSERT ON on that table
INSERT...SELECT the data over to that table
DBCC CHECKIDENT(RESEED) the temp table
Delete the original table and rename the temp table to have the original name