Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Microsoft SQL alternative for Oracle's Imp and Exp command

I'm looking a command line tool or SQL command to export/import a table or complete database. Much like the imp and exp commands of Oracle databases.

Any suggestions?

share|improve this question

migrated from May 11 '11 at 1:36

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Chris S Feb 17 '12 at 16:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I'm not trying to migrate to another server, just export all the tables in the database – Ferdy May 11 '11 at 9:05

If you're running MS SQL Server 2005 I think what you are looking for is Integration Services. This is a product which does many things including import and export. This replaces Data Transformation Services which is your main option on earlier versions.

The easiest way of managing this is to use the Import and Export Wizard in SQL Server Management Studio, although there are other ways of invoking it. Find out more.

share|improve this answer
The problem is that we need to run it from either the commandline or from within an sql statement, since its integrated in our application. – Ferdy May 10 '11 at 12:19

The SQL Server feature that is most like imp or exp is probably bcp. I believe that bcp.exe ships with the "standard" SQL tools. SSIS server objects do not ship with the standard tools and you may run into licensing issues if you are not running your app on the SQL Server.

BCP is a utility that allows data to be exported from a table to a file or imported from a file to a table. BCP has been shipping with SQL Server for something like 20 years, and it is very primitive. It only understands getting data from tables to files or from files to tables. It does not handle creation tables or indexes. It does not handle parent-child relationships. If you need to export/import many tables, you will have to do them one at a time. If you need to create objects on the destination, your best bet is to use the automated script creation features of SSMS to create scripts that will create your tables and indexes. You can then run those scripts on the destination.

BCP uses the standard "fast load" interfaces, which are exposed via OLEDB. If program is written in .Net, you should be able to use those interfaces to code up your own transfers. This would be a better solution than shelling out because you don't have to worry about whether or not a third party utility is on the client machine.

Another way to handle this would be with linked servers, but they tend to be slow and large transfers may require a lot of log file space.

If you need to do this on a regular basis, you might want to look at snapshot replication. This is a server-side solution that requires some set up and configuration.

share|improve this answer
The downside of BCP is that it is not capable of exporting multiple tables. In Exp you can specify FULL=Y to export all the tables. – Ferdy May 11 '11 at 13:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.