Last active
December 20, 2015 23:29
-
-
Save aweigold/6213154 to your computer and use it in GitHub Desktop.
Exporting all tables to CSV in SQL Serverhttp://www.adamweigold.com/2011/11/exporting-all-tables-to-csv-in-sql.htmlThe following script will output a list of statements to use bcp to export all tables to CSV. To use another format, see the bcp documentation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE myDatabase | |
SELECT 'exec master..xp_cmdshell' | |
+ ' ''' | |
+ 'bcp' | |
+ ' ' + TABLE_CATALOG + '.' + TABLE_SCHEMA + '.' + TABLE_NAME | |
+ ' out' | |
+ ' E:\releasedDB\prod\' | |
+ TABLE_CATALOG + '.' + TABLE_SCHEMA + '.' + TABLE_NAME + '.csv' | |
+ ' -c' | |
+ ' -t,' | |
+ ' -T' | |
+ ' -S' + @@SERVERNAME | |
+ '''' | |
FROM INFORMATION_SCHEMA.TABLES | |
WHERE TABLE_TYPE = 'BASE TABLE' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment