Import table and add incremental primary ID
Is there a way to import a table and at that moment include an incremental primary key
I am importing a flat file, but I would like that SQL Server adds it an incremental primary key.
Is there a开发者_开发百科 way, to avoid doing this:
- CREATE TEMPORAL TABLE
- INSERT ALL DATA TO A TEMPORAL TABLE
- ALTER TEMPORAL TABLE AND ADD IT PRIMARY KEY;
I guess doing this costs lots of time...
Like this:
SELECT IDENTITY(int,1,1) AS ID, *
INTO #newtable
FROM dbo.OldTable;
But I would recommend investigating your particular problem and probably solving it using the ranking functions.
精彩评论