-
-
Save adityadeshpande/f2e0ae13447a3fe871d92d06ac097da6 to your computer and use it in GitHub Desktop.
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
$SourceServer = "tcp:servername-s1.database.windows.net" | |
$SourceUserName = "username-u1@servername-s1" | |
$SourcePassword = "password-p1" | |
$TargetServer = "tcp:servername-s2.database.windows.net" | |
$TargetUserName = "username-u2@servername-s2" | |
$TargetPassword = "password-p2" | |
$sourcedatabase = "source-database-name" | |
$targetdatabase = "target-database-name" | |
$bckDirectory = "D:\DataMigration\" | |
$tableNames = @( | |
'Table1', | |
'Table2', | |
'Table3', ... | |
) #Use "SELECT * FROM {database-name}.INFORMATION_SCHEMA.TABLES; GO" to get the tablenames | |
foreach ($table in $tableNames) { | |
$datFilePath = $bckDirectory + $table + ".dat" | |
$sourceinvocationName = $sourcedatabase + ".dbo." + $table | |
#Get Data | |
Write-Host "Geting data for " $sourceinvocationName "output file at " $datFilePath -ForegroundColor Yellow | |
bcp $sourceinvocationName out $datFilePath -c -U $SourceUserName -S $SourceServer -P $SourcePassword | |
$targetinvocationName = $targetdatabase + ".dbo." + $table | |
#Insert Data | |
Write-Host "Inserting data into " $targetinvocationName "from source file at " $datFilePath -ForegroundColor Yellow | |
bcp $targetinvocationName in $datFilePath -c -U $TargetUserName -S $TargetServer -P $TargetPassword | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment