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

Replacing Schema with new schema of Database objects Expand / Collapse
Author
Message
Posted Wednesday, July 01, 2009 12:45 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, August 02, 2009 2:06 PM
Points: 1, Visits: 6
Hi,

I have a schema called "Emp" and all the tables binds to this schema. Now I have created a new schema called "Employee" and wants to bind this new schema "Employee" instead of "Emp". How can I do this with minimal effort.

Also old schema "Emp" is used in my stored procedure and views with tables. I also wants to replace in those stored proc and views.Is there any good script/tool is available for this.

Thanks..
Post #745698
Posted Thursday, July 02, 2009 12:53 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, July 26, 2012 10:06 AM
Points: 267, Visits: 385
This is your answer my friend :)

sp_msforeachtable 'ALTER SCHEMA test TRANSFER ?'
this will change the schema to test .You can change it to employee.

make sure you are in the right database context.

Regards


Abhay Chaudhary
Sr.DBA (MCITP/MCTS :SQL Server 2005/2008 ,OCP 9i)
Post #746020
Posted Thursday, July 02, 2009 8:10 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 6:24 AM
Points: 10,907, Visits: 12,540
Whenever I recommend using sp_MSForEachTable I always include a link to this article which explains the parameters of the procedure and how it works.

I would script out all my procedures, functions, and views and then do a search and replace to change Emp. to Employee.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #746298
Posted Thursday, July 02, 2009 8:46 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, July 26, 2012 10:06 AM
Points: 267, Visits: 385
Nice one Jack ....
Cheers


Abhay Chaudhary
Sr.DBA (MCITP/MCTS :SQL Server 2005/2008 ,OCP 9i)
Post #746734
Posted Friday, July 03, 2009 12:23 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: 2 days ago @ 7:01 AM
Points: 734, Visits: 3,554
Hi,

Try this:


set the o/p mode to text in SSMS .. then run the following .....

SELECT 'ALTER SCHEMA Employee TRANSFER ' + TABLE_SCHEMA + '.' + TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'EMP'

sp_msforeachtable


this is an undocumented procedure ... it is very handy but not recommended by Microsoft.

Also old schema "Emp" is used in my stored procedure and views with tables. I also wants to replace in those stored proc and views.Is there any good script/tool is available for this.


I would go with what Jack suggested ....
I would script out all my procedures, functions, and views and then do a search and replace to change Emp. to Employee.


Hope this helps ...

Happy 4th of JULY !

Thanks,
\\K


______________________________________________________________________________________________________________________________________________________________________________________
HTH !
Kin
MCTS : 2005, 2008
Active SQL Server Community Contributor
Post #747081
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse