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.
| 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 Table1truncate table table2truncate table table3copy c:\test\data\Table1.txt into servername..Table1 copy c:\test\data\Table2.txt into servername..Table2copy c:\test\data\Table3.txt into servername..Table3What 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" utilityAbout both of those u can find more info, from BOLAlso read "command prompt, (See also command prompt utilities)" in BOL |
 |
|
|
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. |
 |
|
|
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. |
 |
|
|
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 |
 |
|
|
|
|
|