0

I have a SQL database with 4 tables in SSMS 2017.

Currently I am exorting them one by one using Right Click > Tasks > Export data and following the pop-up boxes in SQL Server Import and Export Wizard.

Anyone know if I can write a query to loop the export of all of them to different named files?

2
  • What's the names of your tables Commented Sep 13, 2018 at 6:22
  • dbo.x1; dbo.x2; dbo.x3; dbo.x4 Commented Sep 13, 2018 at 11:38

1 Answer 1

1

There are numerous way to export data from SQL Server, please see most(if not all) of the options here - http://www.sqlservercentral.com/articles/Export/147145/

I would personally go with automating it true PowerShell, below you can see how to export it for a single table:

Run in PowerShell:

Import-Module SQLPS
$SQLCommand = “SELECT * FROM [AdventureWorks].[Production].[Products]”
Invoke-Sqlcmd -query $SQLCommand | Export-Csv -Path C:\Export.csv -NoTypeInformation

You can of course work to automate it, prepare a list of the tables you need and go with a for each loop true all of them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.