Created
November 2, 2020 17:45
-
-
Save adityadeshpande/310212707a31a829e8f25959dfe37c68 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" | |
$database = "database-name" # Kept same for simplicity. | |
$bckDirectory = "D:\DataMigration\" | |
$tableNames = @( | |
'Table1', | |
'Table2', | |
'Table3', ... | |
) #Use "SELECT * FROM {database-name}.INFORMATION_SCHEMA.TABLES; GO" to get the tablenames | |
foreach ($table in $tableNames) { | |
$invocationName = $database + ".dbo." + $table | |
$datFilePath = $bckDirectory + $table + ".dat" | |
#Get Data | |
Write-Host "Getting data for " $invocationName "output file at " $datFilePath -ForegroundColor Yellow | |
bcp $invocationName out $datFilePath -c -U $SourceUserName -S $SourceServer -P $SourcePassword | |
#Insert Data | |
Write-Host "Inserting data into " $invocationName "from source file at " $datFilePath -ForegroundColor Yellow | |
bcp $invocationName 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