Last active
March 11, 2024 20:06
-
-
Save lrhache/6e644018c417bb22007e to your computer and use it in GitHub Desktop.
Export all tables from a database to CSV files - AWS MSSQL 2008 / Win 2008
This file contains 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
set-alias installutil $env:windir\microsoft.net\framework\v2.0.50727\installutil | |
installutil -i "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist\Microsoft.SqlServer.Management.PSProvider.dll" | |
installutil -i "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist\Microsoft.SqlServer.Management.PSSnapins.dll" | |
Add-PSSnapin SqlServerCmdletSnapin100 | |
Add-PSSnapin SqlServerProviderSnapin100 | |
$SERVER_NAME="<SERVER NAME>"; $DB_NAME="<DB NAME>";$Tables = invoke-sqlcmd -query "SELECT name FROM sys.tables order by name" -database $DB_NAME -serverinstance $SERVER_NAME;foreach ($Table in $Tables){$TableName = $Table["name"];write-host -ForegroundColor Green "Creating File $TableName.csv";invoke-sqlcmd -query "SELECT * FROM $TableName" -database $DB_NAME -serverinstance $SERVER_NAME |export-csv -path D:\dump\$TableName.csv;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment