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!
18 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.
Saved me loads of time... thanks
Really, thank you man....
Thank you very much.
Alhamdulillah
this is great! many thanks! very much helpful!
I get this error:
Msg 15151, Level 16, State 1, Line 1
Cannot transfer the object 'Cost_Of_Package', because it does not exist or you do not have permission.
Any help out there ?
Really thank you. It is saved lot of my time
yea it's work!!
great :)
It's really helped and also saved lot of time
Thank you very much.
Fantastic. Thank you.
Post a Comment