开发者

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:

  1. CREATE TEMPORAL TABLE
  2. INSERT ALL DATA TO A TEMPORAL TABLE
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜