Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mary_itohan
Posting Yak Master
191 Posts |
Posted - 2014-04-25 : 09:11:49
|
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 valuethanksMBULK INSERT CSV_TESTINGFROM 'd:\MAM-NAP.csv'WITH(FIELDTERMINATOR = ',',ROWTERMINATOR = '\n');_____________________Yes O ! |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2014-04-25 : 10:11:12
|
No problem bulk inserting to a table with a PK.>>However I noticed it does not allow any primary keyNot 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 OptimizerTG |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-04-25 : 11:33:48
|
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. http://technet.microsoft.com/en-us/library/ms188365.aspx |
|
|
|
|
|