Skip to content

Instantly share code, notes, and snippets.

@alevyinroc
Last active November 14, 2018 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alevyinroc/f751d0f5063ae863b930d8c2ae5a55e7 to your computer and use it in GitHub Desktop.
Save alevyinroc/f751d0f5063ae863b930d8c2ae5a55e7 to your computer and use it in GitHub Desktop.
Copies a database table including definition
$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