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
 General SQL Server Forums
 New to SQL Server Programming
 SQL backup to text file

Author  Topic 

Trininole
Yak Posting Veteran

83 Posts

Posted - 2010-01-25 : 15:55:03
Is there a way to back-up multiple tables to multiple text files without using BCP utility or the standard export wizard in SQL 2005?
For example, i have five tables and i would like to write these five tables to their own five text files all at the same time.

Roger DeFour

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-01-25 : 16:02:54
Why is BCP or the export wizard unsuitable for this?

CODO ERGO SUM
Go to Top of Page

Trininole
Yak Posting Veteran

83 Posts

Posted - 2010-01-25 : 16:06:08
The BCP will work, but Im not great at DOS. The export wizard will take multiple tables and export into one file but not taking 5 tables and putting those 5 tables into 5 separate text files.


Roger DeFour
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-01-25 : 16:31:35
you don't need to be great at DOS. just follow the directions in BOL for BCP and you'll end up with 5 text files

here...create a text file that looks like this:

bcp "SELECT * FROM database..table1" queryout c:\dba\table1.txt -c -Sservername -T
bcp "SELECT * FROM database..table2" queryout c:\dba\table2.txt -c -Sservername -T
bcp "SELECT * FROM database..table3" queryout c:\dba\table3.txt -c -Sservername -T
bcp "SELECT * FROM database..table4" queryout c:\dba\table4.txt -c -Sservername -T
bcp "SELECT * FROM database..table5" queryout c:\dba\table5.txt -c -Sservername -T
changing "database", "table" and "servername" to the actual database table and server names and change the path to the files you want to create.

then save it with a .cmd extension and execute it
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-01-26 : 03:09:55
You can also run BCP from a SQL command (although that does require that SQL is set to allow such "DOS commands" to be run from SQL, so might not be an option for you)
Go to Top of Page
   

- Advertisement -