Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 bcp

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2006-03-14 : 10:41:26
Hello,
I would like to write a bcp (i.e. .bat file) which truncates the sql server tables and then takes the .txt files and imports them into the related tables in sql server.

Something like:

truncate table Table1
truncate table table2
truncate table table3

copy c:\test\data\Table1.txt into servername..Table1
copy c:\test\data\Table2.txt into servername..Table2
copy c:\test\data\Table3.txt into servername..Table3

What is the syntax for these in BCP please?

Thanks

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-03-14 : 11:04:22
BCP is Bulk Copy and is not doing (as far as I know) anything other than inserting data to SQL Server. U r correct in the sense, it can be run by a batch file.

For ur requirement, u may need to use "isql" utility

About both of those u can find more info, from BOL
Also read "command prompt, (See also command prompt utilities)" in BOL
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-03-14 : 11:29:04
It's osql not isql for v2000 (although isql still works).
You might be better doing this as a stored proc using bulk insert rather than bcp.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2006-03-14 : 11:58:52
That may be the case but I need to pass the .txt file name and then pass the database name.
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2006-03-14 : 17:33:55
You can do both within a batch file:

osql -Uuser -Ppassword -Sserver -ddatabase -Q"truncate table table1"
bcp database..table1 c:\test\data\table1.txt -c -Uuser -Ppassword -Sserver

Go to Top of Page
   

- Advertisement -