Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Export SQL data to a file Expand / Collapse
Author
Message
Posted Wednesday, February 20, 2013 1:11 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, February 20, 2013 2:23 PM
Points: 8, Visits: 15
I occasionally have need to export data from a MSSQL database to a file, copy the file to another server on a different network, then import the data from the file into a different MSSQL database. In the past I've done this by exporting the data to an Access database file, but on newer machines with Office 2010, Access isn't included. Sometimes I need to do large amounts of data from many tables, so using a flat file or Excel wouldn't work well. What would be the recommended way to handle this sort of thing?

Thanks,
Andy
Post #1422270
Posted Wednesday, February 20, 2013 1:26 PM


Default port

Default portDefault portDefault portDefault portDefault portDefault portDefault portDefault port

Group: General Forum Members
Last Login: Friday, November 21, 2014 12:51 PM
Points: 1,433, Visits: 3,230
You should use bcp utility. It is included as apart of every SQL Server installation. It is a command line utility, you specify what data is to be exported via command line parameters to a given file, then you can use bcp to bulk insert the same file to a table on the destination server.

There are lots of command line option and you can look up the details in BOL but in the simplest case, going from SQL server to SQL Server you can use:

output:

bcp "select query" queryout destFilePath -k -N -Sserver -T

input at destination:

bcp dbname.dbo.tablename in destFilePath -E -k -N -Sserver -T







The probability of survival is inversely proportional to the angle of arrival.
Post #1422282
Posted Wednesday, February 20, 2013 3:57 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 8:13 PM
Points: 356, Visits: 921
Depending on what is meant by "copy the file to another server on a different network", bcp may run into permissions issues.

I'd take a look at using SSIS for this and make a package to do the work for you. It may have a steeper learning curve than BCP but it can be more flexible.
Post #1422343
Posted Wednesday, February 20, 2013 4:47 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 5:24 PM
Points: 1,805, Visits: 5,867
ajreynolds (2/20/2013)
I occasionally have need to export data from a MSSQL database to a file, copy the file to another server on a different network, then import the data from the file into a different MSSQL database. In the past I've done this by exporting the data to an Access database file, but on newer machines with Office 2010, Access isn't included. Sometimes I need to do large amounts of data from many tables, so using a flat file or Excel wouldn't work well. What would be the recommended way to handle this sort of thing?

Thanks,
Andy


create a new database
copy the tables to it
detach it/back it up
copy it to remote server
attach it/restore it
copy data to desired location

This can of course be scripted as well, just to make life simpler.


MM


  • MMGrid Addin
  • MMNose Addin


  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • Post #1422355
    « Prev Topic | Next Topic »

    Add to briefcase

    Permissions Expand / Collapse