1

...if you have a long list of names of tables to transfer, and you'd rather not having to mark their check-boxes in a wizard one by one?

6
  • what do you mean copy tables in a list? You want to copy X number of tables (and their rows) from one server to the next? Commented Jun 7, 2018 at 16:30
  • @scsimon: I have a list of table names that I need to copy from a database with even more tables to another database missing those tables. I'd rather feed that list to a script or something than use a wizard and having to mark the tables manually, since it is a long list. Commented Jun 7, 2018 at 16:39
  • So you don't want to do this method if i understand you correctly? Commented Jun 7, 2018 at 16:54
  • I won't post this as an answer, but it seems to be what you are trying to do. I'd just caution that it could take a long time depending on the data and table list. I'd break it up in batches. Also, I'd watch your transaction logs and increase their backup frequency. Commented Jun 7, 2018 at 16:58
  • @scsimon: Thank you for that information, but, as I mentioned in the title, I need to copy structure as well (create the tables anew), not just transfer data. Commented Jun 7, 2018 at 17:09

1 Answer 1

2

Bitoolean,

Take a look at dbatools for powershell. Soulds like their toolset may be of use. I know they have a migration tool in there.

dbatools can be found here https://dbatools.io/

Also, You could look at https://sqljana.wordpress.com/2017/06/12/powershell-copy-sql-server-tables-structure-data-indexes-to-another-databaseinstance/ which seems to detail method in powershell to do what you wanted and have the $tables variable populated from a text file list or SQL Query.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. As far as I can see in the command list though, the DBATools is only useful for automating copying of entire databases though (Copy-DbaDatabase)?
dbatools seems to have commands for copying every other object, but not tables.
bitoolean, Take a look at this blog post [link]:(sqljana.wordpress.com/2017/06/12/…) From the looks of it you can import a list of tables into an array variable and call it directly (In the usage section the $tables variable could read from a SQL Query or text file)
Thank you. I will look into it. You should probably post that as an answer. For now I've resorted to using SSIS packages to at least prevent having to repeat the clicking for the same list when I have to copy the same tables more than once. The question is still valid though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.