Sunday, February 19, 2012

Exporting to textfiles

Hi,
I have a SQL 2000 db with 140 tables. I want to export all tables to
textfiles. If I use Tool | Export data I only can export one table each
time.
Is there any way to export all tables automatically (I want the resulting
textfiles to have the same name as the original db table)?
Regards
PO
Hi,
You can write a BCP OUT command for Information_schema.Tables
Execute the below script in Query analyzer with Text result. Paste the
output of the result in a new Query window and execute. This will export the
table data to text files in c:\backup folder with the table name as the text
file name.
use <dbname>
go
set quoted_identifier off
select 'master..xp_cmdshell '+"'"+bcp pay..'+table_name+' out
c:\backup\'+table_name+'.txt -Usa -Phari -Sa266uss\harisql -c'+"'"
+char(10)+'go' from information_schema.tables where +table_type='BASE TABLE'
Thanks
Hari
MCDBA
"PO" <po> wrote in message news:e1$nZ0YaEHA.1048@.tk2msftngp13.phx.gbl...
> Hi,
> I have a SQL 2000 db with 140 tables. I want to export all tables to
> textfiles. If I use Tool | Export data I only can export one table each
> time.
> Is there any way to export all tables automatically (I want the resulting
> textfiles to have the same name as the original db table)?
> Regards
> PO
>

No comments:

Post a Comment