I am using SQL Server 2012 and am creating a table in the following way:
SELECT x, y
INTO CampRegistration
FROM tableA
UNION
SELECT x, y
FROM tableB
x and y are not primary keys. I wish for the CampRegistration table to have an additional column that is an integral surrogate primary key ie. something like an IDENTITY.
How can I do this, either by modifying the SELECT INTO or adding and populating the column afterwards?
The other answers add the row number but don’t make it a key and also don’t help when you want to add a new registration. Here is how, after you’ve run your SELECT INTO, you can add an IDENTITY column and make it the key: