Peter Larsson Blog

Patron Saint of Lost Yaks

Change schema for all tables

I just helped a guy here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=98346 with schema
and thought that someone could benefit from this code

exec

 

 

sp_MSforeachtable "PRINT '? modify'; ALTER SCHEMA new_schema TRANSFER ?; IF @@ERROR = 0 PRINT '? modified'; PRINT ''"

Legacy Comments


Chris
2012-05-27
re: Change schema for all tables
This little piece of code has helped me so many times! Thanks for sharing!