MS SQL Server/Foreign Key Error upon Loading tables with BCP
Hello, I have a tool that performs manipulations on data and then loads the data into a database. I have been using an option whereby rows are inserted into the DB one by one. This is a tried and true process. However to address time issues, I have been experimenting with another option: bulk loading entire tables into the db, using BCP.
The data is processed in batches and for most batches, the load process seems to run without problems, but the error message shown below or " Loader ended with ExitCode -1073741819" will be shown at the very end of the load process.
My question: can you please help me troubleshoot the foreign key error I am getting, shown below? I am working to identify a workaround, and very much appreciate any help you can lend.
SQLState = 23000, NativeError = 2627 Error = [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Violation of PRIMARY KEY constraint 'PK_bdx_aaaaa_bbbb'. Cannot insert duplicate key in object ....
From what I can tell, you are not encountering a foreign key error. This appears to be a PRIMARY KEY violation. Look at the columns in PK_bdx_aaaaa_bbbb and make sure that there are no duplicates for those columns in your input file. It would help if you sent me a the DDL for the table in question (including indexes and keys).
Also, included what version of SQL Server you're using.