Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

Export all table data to Text file

Jul 5 2010 5:16AM by Madhivanan   

One of my friends asked me if it is possible to export each table's data to each text file so that
those files can be used in another system for data import?
The point is he wanted to move database from SQL Server to Mysql. But there was not possible to have a
connectivity between the two systems. He generated the script but exporting data was the problem.

I suggested him to run this script that will take all userdefined table's data to each file where filename is the table name itself

declare @tables table(table_name varchar(100))

insert into @tables
select name from sysobjects where xtype ='u'



declare @table_name varchar(1000)

select @table_name=min(table_name)from @tables

while @table_name>''
Begin
        Declare @str varchar(1000)  
        set @str='Exec Master..xp_Cmdshell ''bcp "Select * from '+db_name()+'..'+@table_name+'"
         queryout "C:\data\'+@table_name+'.txt" -c'''  
        Exec(@str)  
		select 
                        @table_name=min(table_name)
                  from 
                        @tables 
                  where 
                        table_name>@table_name

End 

Tags: t-sql, sql_server, bcp, tsql, BRH, SQL Server, export_data, #TSQL,


Madhivanan
3 · 39% · 12440
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

3  Comments  

  • Useful post, Madhivanan. Here's another style - same thing, just condensed into one single line:

    exec spMSforeachtable 'Exec Master..xpCmdshell ''bcp "select * from AdventureWorks2008.?" queryout "C:\Data\?.txt" -S "SQL2K8\SQL2K8R2" -T -c'''

    commented on Jul 23 2010 1:33PM
    nakul_vachhrajani
    2895 · 0% · 2
  • nakul_vachhrajani,

    Yes. That is easy in one line. But note that sp_MSforeachtable is undocumented and can be removed from future release

    commented on Jul 26 2010 3:57AM
    Madhivanan
    3 · 39% · 12440
  • e.g. from VFP ! /N bcp Npanxx_2000.dbo.geofnl out c:\temp\geofnl.txt -c -t, -T -S192.168.253.145 where:

    ! /N - is a VFP call for running a cmd

    Npanxx_2000.dbo.geofnl - database name.dbo.table name

    c:\temp\geofnl.txt - txt file path to export to

    -c -t, -T -S - switches (explained all over) 192.168.253.145 - server IP address where the SQL database resides

    commented on Aug 4 2011 4:26PM
    Yehuda Epstein
    2895 · 0% · 2

Your Comment


Sign Up or Login to post a comment.

"Export all table data to Text file" rated 5 out of 5 by 1 readers
Export all table data to Text file , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]