3

I'm loading 2 csv files into 2 tables in SQL Server Data Tools using SSIS, and the 2nd one is connected to the 1st via a foreign key constraint. The problem is that a row of the 2nd table has a key that is missing from the 1st table, so the foreign key constraint fails and an error message is presented.

Is there a way to check the foreign key constraint before insertion and catch the error so that it doesn't interrupt the insertion of the rest of the rows?

1 Answer 1

1

IN SSIS, you can probably set up a lookup step with the foreign key data from table 1; rows that don't match could be routed into an error file, and the rest routed into the table.

Alternately, load the data into a staging table without the foreign key constraint, and run a script/stored procedure to validate the data in the staging table, including making sure the foreign keys are present.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.