Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 bulk insert does not allow primary key
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

191 Posts

Posted - 04/25/2014 :  09:11:49  Show Profile  Reply with Quote
Hello guys,
I am using the bulk insert statement below to import data from a csv and excel files. As I am running 64bit versions of windows, and could not find any sql import statements.

However I noticed it does not allow any primary key, hence after importing to the temp table, I then import in sql to the main table.

Is there anyway to fix the temp table ? ie add a PK value



FROM 'd:\MAM-NAP.csv'


Yes O !

Flowing Fount of Yak Knowledge

6065 Posts

Posted - 04/25/2014 :  10:11:12  Show Profile  Reply with Quote
No problem bulk inserting to a table with a PK.

>>However I noticed it does not allow any primary key
Not sure what you mean by this. If you put a primary key on the target table or not Bulk Insert will insert to it. Of course your data can't violate that constraint otherwise the operation will fail. So in that regard I think it is good practice to bulk insert to a staging table anyway.

Be One with the Optimizer

Edited by - TG on 04/25/2014 10:12:48
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 04/25/2014 :  11:33:48  Show Profile  Reply with Quote
Also: if your PK column is an identity column, and you want to import the values of that column into the table, you will need to specify the KEEPIDENTITY option in BULK INSERT.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000