I am trying to import 100 records into SQL Server using BCP. Suppose if 51st record fails because of bad data. I am unable to rollback previous 50 records when 51st record fails. How to rollback entire import operation when there is a error during BCP import.
Thanks for the help.
You won’t be able to rollback because the SQL logging that enables the rollback is turned off when using BCP. Being able to move large amounts of data without the overhead of log maintenance is the primary benefit of BCP. I don’t know your specific situration, but you may consider performing your BCP import into a temporary table first in order to make sure it completes successfully. Then you can drop the temporary table on a failure, effectively rolling back the transaction, or move a successful result to your permanent storage.