-1

Is there any way to export data from different schemas which resides in SQL server without using SQL Import & Export wizard ?

I have almost 400 tables which are split across different databases. Right now, I am using SQL Import & Export wizard where for each table, I have to open the SQL Import/Export wizard which does the export and would require to redo the same process for rest 399 tables & more.

Is there any SQL query or any auto process where we can export the data from different schemas in SQL server in one go?

Please help me on this, any pointers would be appreciated.

Thank you in advance.

2 Answers2

1

You can use bcp utility (more info here).

Here is a simple command to export the data in csv format from a table [SCHEMA_NAME].[TABLE_NAME] from the database [DB_NAME]:

bcp [DB_NAME].[SCHEMA_NAME].[TABLE_NAME] out C:\data.csv -c -T -t,
Andrea
  • 11,801
  • 17
  • 65
  • 72
1

Check Export table from database to csv file answer here:

Using SQLCMD (Command Prompt):

From the command prompt, you can run the query and export it to a file:

sqlcmd -S . -d DatabaseName -E -s',' -W -Q "SELECT * FROM TableName" > C:\Test.csv

Notes:

  1. This approach will have the "Rows affected" information in the bottom of the file, but you can get rid of this by using the "SET NOCOUNT ON" in the query itself.

  2. You may run a stored procedure instead of the actual query (e.g. "EXEC Database.dbo.StoredProcedure")

  3. You can use any programming language or even a batch file to automate this

Using ApexSQL tool:

Export SQL Server data to CSV by using the ApexSQL Complete Copy results as CSV option.

The Copy code as is a feature in ApexSQL Complete, a free add-in for SSMS and Visual Studio, that copy the data from the Results grid to a clipboard in one of the following data files: CSV, XML, HTML in just one click.

In a query editor, type the following code and execute:

Example:

USE AdventureWorks2014

SELECT at.* FROM Person.AddressType at

In the Results grid, select the part or all data, right click and from the context menu, under the Copy results as sub-menu, choose the commands like CSV, XML & HTML

This will copy the selected data from the Results grid to the clipboard. Now, all that needs to be done is to create a file where the copied data should be pasted:

The ApexSQL Complete Copy code as an option can save you a great amount of time when you need to copy repetitive SQL data to another data format.

CR241
  • 2,293
  • 1
  • 12
  • 30