Last active
November 14, 2018 16:58
-
-
Save alevyinroc/f751d0f5063ae863b930d8c2ae5a55e7 to your computer and use it in GitHub Desktop.
Copies a database table including definition
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 = "MYSOURCE"; | |
$SourceDB = "MySourceDB"; | |
$DestDB = "MyDestDB"; | |
$TableName = "MyTable"; | |
# Get the table definition from the source | |
$tablescript = Get-DbaDbTable -ServerInstance $SourceServer -Database $SourceDB -Table $TableName | Export-DbaScript -Passthru; | |
# Run the script to create the table in the destination | |
Invoke-DbaQuery -Query $tablescript -ServerInstance $SourceServer -Database $DestDB; | |
# Copy the data | |
Copy-DbaDbTableData -ServerInstance $SourceServer -Database $SourceDB -DestinationDatabase $DestDB -Table $TableName -DestinationTable $TableName; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment