Skip to content

Instantly share code, notes, and snippets.

@ScottGuymer
Last active October 24, 2015 13:14
Show Gist options
  • Save ScottGuymer/b16319b00f9650f822c5 to your computer and use it in GitHub Desktop.
Save ScottGuymer/b16319b00f9650f822c5 to your computer and use it in GitHub Desktop.
Create a list of commands to dump all tables to csv
select 'exec master..xp_cmdshell'
+ ' '''
+ 'bcp'
+ ' "' + TABLE_CATALOG + '.' + TABLE_SCHEMA + '.[' + TABLE_NAME + ']"'
+ ' out'
+ ' "C:\temp\'
+ 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