Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to change the schema prefix for a table when using Transfer SQL Server Objects Task Expand / Collapse
Author
Message
Posted Thursday, October 11, 2012 9:11 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 12:00 PM
Points: 281, Visits: 625
I am wanting to use Transfer SQL Server Objects Task to copy tables and their data from one database to another but the hitch is that where the table is in the dbo schema in the source database but it needs to be on another schema on the destination. I know I can copy them over using the dbo schema and run tsql to update the schema but how do I handle tables that are in schemas on the source that dont exist in the destination? For example [DansSchema].[DansTable] on source database needs to go to [NewSchemaName].[DansTable]. DansSchema doesnt exist on the destination db.
Post #1371573
Posted Thursday, October 11, 2012 9:39 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 12:00 PM
Points: 281, Visits: 625
I've come up with a possible work around. If you have permission to run Exe SQL Task to update the schema on the source to the dbo schema which more than likely will exist on both databases, copy the table over into the dbo schema in the destination, Update the src tables back to original schema, then update the destination to the desired schema in anothe exe sql task.
Post #1371609
Posted Monday, October 15, 2012 4:13 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 12:00 PM
Points: 281, Visits: 625
Actually went in this direction. I created the missinig schemas on my destination db, ran the obj transfer, then ran the following to move all tables into the corrrect schema


exec sp_MSforeachtable 'ALTER SCHEMA [Schema to Move To] TRANSFER ?'

Then I dropped the unneeded schemas.


Post #1372983
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse