BULK INSERT with identity (auto-increment) column

前端 未结 9 1400
情话喂你
情话喂你 2020-11-29 02:57

I am trying to add bulk data in database from CSV file.

Employee table has a column ID (PK) auto-incremented.

CREATE TABLE [dbo].[Employ         


        
9条回答
  •  伪装坚强ぢ
    2020-11-29 04:02

    Another option, if you're using temporary tables instead of staging tables, could be to create the temporary table as your import expects, then add the identity column after the import.

    So your sql does something like this:

    1. If temp table exists, drop
    2. Create temp table
    3. Bulk Import to temp table
    4. Alter temp table add identity
    5. < whatever you want to do with the data >
    6. Drop temp table

    Still not very clean, but it's another option... might have to get locks to be safe, too.

提交回复
热议问题