0

I am trying to export a database within Microsoft SQL Server Management Studio 2000. My database is extremely large with over 1,300 unique tables.

I am aware of the export wizard and copy/paste options but am looking for something that would allow me to export all 1,300 tables (or at least a few hundred at once) into a single csv or xls file. Copy and pasting or selecting "save as" for each table would take far too long and the export wizard only allows a few dozen tables at a time.

12
  • 3
    What would a single csv/xls file look like that contained 1300 tables? Commented Jun 13, 2018 at 21:18
  • Do you really have to do it from within SSMS? Scripting the exports using sqlcmd or some other script processor would allow you to export them all at once, and should require less of your time.. Commented Jun 13, 2018 at 21:26
  • @dfundako An excel workbook would consist of 1300 sheets, each representing a table. Commented Jun 13, 2018 at 21:30
  • @JohnDoe I would enjoy seeing people scrolling through that. Also, excel workbooks only can do a million or so rows, so keep that in mind. Commented Jun 13, 2018 at 21:33
  • 2
    I guess I'll speak for everyone here if I ask why a single file like Excel would be of advantage. Most probably CSV files for each table would be much easier to tackle the problem. Just because you'd have to access to a single Excel file, it doesn't mean the tasks gets easier because you'd still have the sheets. Besides, I'd be not surprised if 1300 sheets would hit some sort of limit by Excel. They point is, a such idea would be highly experimental in my opinion and I wouldn't do that for production stuff Commented Jun 14, 2018 at 5:59

2 Answers 2

1

Well , I would not recommended you to do this, but if you desperately need a solution in the way you have described , here it is :

First , run this query on the database :

    SELECT 'sqlcmd -S . -d '+DB_NAME()+' -E -s, -W -Q "
    SET NOCOUNT ON;
    SELECT * FROM '+table_schema+'.'+TABLE_name+'" > "C:\Temp\'+Table_Name+'.csv"' 
    FROM [INFORMATION_SCHEMA].[TABLES]

You might want to change the folder name as per your convenience

Second, Copy all the rows returned into a Export.bat or Export.cmd file

Third, run the Export.bat file to get 1300 odd tables you need in separate CSV files

Fourth, open a cmd window , navigate to the folder you have your files in and use the following command :

copy *.csv Export.csv

You will have a single Export.csv file containing all your tables, along with headers for each table

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

2 Comments

For SQL authentication, use : SELECT 'sqlcmd -S . -d '+DB_NAME()+' -U [username] -P [password] -s, -W -Q "SET NOCOUNT ON;SELECT * FROM '+table_schema+'.'+TABLE_name+'" > "C:\Temp\'+Table_Name+'.csv"' FROM [INFORMATION_SCHEMA].[TABLES]
Also , regarding your remote connections issue, you might wan't to try this : EXEC sp_configure 'remote access',1 reconfigure
0

Perhaps this will help you to resolve your problem.

SQL Server Management Studio 2012 - Export all tables of database as csv

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.