March 7, 2008 at 7:39 am
I want to BULK INSERT a .csv file to a table and have the table autogenerate a PK for each row. Is there a way to do this directly? Or would I have to use a staging table?
March 7, 2008 at 7:47 am
by "auto-generate primary key", i assume you're referring to an identity column. if so, we typically add the identity column as the last column of the table, then create a bcp fmt file and remove the identify column from the fmt file. using that fmt file, you'll be able to bcp in the data to the table and the identity column will be populated.
March 7, 2008 at 7:48 am
Hi,
As long as the column on the table has the identity property turned on, this will autogenerate a value for each row imported.
Thanks,
Phillip Cox
MCITP - DBAdmin
March 7, 2008 at 8:37 am
Hi,
As long as the column on the table has the identity property turned on, this will autogenerate a value for each row imported.
You still need the format file, so that bcp does not try to import into the identity column.
Edit: resolved a bad closing quote tag.
March 7, 2008 at 8:41 am
Thanks all! I'll get started with a bcp.fmt
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply