Blog Post

SQL Server Integration Services (SSIS) Blog
1 MIN READ

Transfering a couple of tables at a time

SSIS-Team's avatar
SSIS-Team
Copper Contributor
Mar 25, 2019
First published on MSDN on Oct 31, 2007

I missed some of the comments to my post about creating your own http://blogs.msdn.com/mattm/archive/2007/04/18/roll-your-own-transfer-sql-server-objects-task.aspx , so I thought I'd post the answer here incase people miss my answer.

You can use the http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.transfer.objectlist.aspx of the http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.transfer.aspx object to specify which database objects you want to transfer. To transfer only certain tables from a database, you'd set CopyAllTables to false, and then add http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.table.aspx objects to the object list.

Note, when accessing the Tables collection of the Database object, you can specify the table by index or by name. You can also use an additional schema name parameter if there are duplicate table names in separate schemas.

Database sourceDB = new Database("source");

Transfer xfer = new Transfer(sourceDB);

xfer.CopyAllTables = false;

[...]

xfer.ObjectList.Add( sourceDB.Tables["table1"] );

xfer.ObjectList.Add( sourceDB.Tables["table2", "schema1"] );

xfer.ObjectList.Add( sourceDB.Tables["table2", "schema2"] );

xfer.ObjectList.Add( sourceDB.Tables["table3"] );

Updated Mar 25, 2019
Version 2.0
No CommentsBe the first to comment