I want to empty a temporary table, load it via bcp, and then modify its rows before moving to a production table. The commands would look something like this:
- truncate table temp1
- bcp db.schema1.temp1 in import1.txt -h "TABLOCK"
- exec sp_modify_temp1_rows_move_to_production_table
My question is how can I execute all this as one transaction, not necessarily in the interest of rolling it back, but in order to provide isolation.
Here is the imagined scenario. User1 goes to load import1.txt (the implementation details of how this done, steps 1-3, are hidden to the user). Before step 2 finishes for User1, User2 initiates their own import. Locking mechanisms prevent their import from starting right away. The primary concern is that User2 step 1 will begin as soon as User2's step 2 is done thus clearing the table before User1's step 3 and the process can be completed.
Three additional notes:
- Client side execution here via ADO (not to be mistaken with ADO.NET)
- BULK INSERT is NOT an option
- Prefer doing this via extending some lock mechanism via ADO that can include step 2 in with steps 1 and 2 of the process - if possible - knowing that it is impossible helps here also
Edit: marc_s - please don't change my post with a personal opinion of how to name the product. Do a search on Wikipedia or Microsoft's Bing or here at Stack Overflow for MSSQL. I already tagged the post as sql-server. MSSQL is another search parameter a person may want to use. Its not my fault that this is a common acronym. If you have some link to provide as to why its particularly harmful to use this alias then please provide. Otherwise it looks like you are going out of your way to force your views on others. Thanks.