DbaTools Related - https://dbatools.io/functions/
Hello,
I am trying to find a solution to copy a table and create it on the -Destination / -DestinationDatabase, please.
I am using:
Get-DbaTable -SqlInstance "Machine1" -Database DBA -Table "Table01" | Copy-DbaTableData -Destination "Machine2\PANDA" -DestinationDatabase PANDA01 -DestinationTable "Table01"
But the since the table is not created on the destination, I get error message:
WARNING: [15:25:58][Copy-DbaTableData] Table01 does not exist on destination
Is there any way I copy and create the table on DestinationDatabase, please?
This is something which I had used for a similar task -
The above will script out all the tables from source database to text files and then read the same from text files and create the tables on target database and target server. Few things to keep in mind -
dbo, then you need to create those schemas first. Else your tables for other schemas won't be created.$trueor$falsefor database objects as per your requirement.You could have this
Get-DbaTable -SqlInstance "Machine1" -Database DBA -Table "Table01" | Copy-DbaTableData -Destination "Machine2\PANDA" -DestinationDatabase PANDA01 -DestinationTable "Table01"run after the tables are created or you can loop in the script after the create tables itself, so that table creation and loading of data into the tables happen simultaneously. That is entirely your choice and I leave it at your discretion. Hope this helps!