Sql Server 2005: Change schema for all tables
I recently needed to change the schema for all the tables in a Sql Server 2005 database.
Sql Server 2005 provides a T-SQl statement capable to change the schema for a given object called ALTER SCHEMA
You may use the following syntax to change the schema for all the tables in a database. Just change the "new_schema" string with the desired one:
exec sp_MSforeachtable "ALTER SCHEMA new_schema TRANSFER ? PRINT '? modified' "
Enjoy!


9 comments:
Thanks a lot! It worked great!
Renato - Brazil
I'm glad to hear that! :)
After "banging my head" one at a time through the first 20 tables...
Did a search found your script, THANKS!!!
U Rock!
thanks! this is 100000K helpful!!
:-)
Man, I've been fighting with this for 2 hours, and this one line fixed the problem in 10 seconds. Thanks!
Nicely done! It worked for me too!
Nice one Ruslan, worked a treat! Many thanks :)
Many thanks! That really helped me.
slashi@gmail.com
Awesome command.
Post a Comment