SQL 2000 Import using BCP

Soldato
Joined
17 Nov 2005
Posts
3,108
Location
Swindon, UK
Hello,

SQL 2000 on Windows Server 2003

I was wondering if you all could help.

I have a DOS Batch file that imports data into a SQL 2000 DB using BCP. I want to clear out the exisitng data first and trucate the table using OSQL.

Code:
osql -dMy_Data -E -Smyserver -Q "BEGIN TRANSACTION MyTransaction TRUNCATE TABLE film COMMIT TRANSACTION MyTransaction"

bcp My_Data.dbo.film in film.txt -q -n -t -T -Smyserver

Obviously if it all went wrong, how would I rollback so that the original tables weren't truncated using the batch file?

Can the OSQL and BCP commands work together in a SQL transaction within a DOS Batch file?
 
Thanks for the reply akakjs.

I still couldn't figure out how to get the file to read in as well as doing a truncate on the same BCP line.

It was just a temporary solution, before the whole lot gets scripted elsewhere.

But it was one of those tasks that were bugging me, so I'd thought I'd ask on here.

Ta

Andrew.
 
Back
Top Bottom