SQL Server 2008 – Change multiple Table Schemas at once

by Joseph on Apr 6th in SQL Server, SQL Server 2005, SQL Server 2008, Table Schema

Need to change all the table schemas at one time? In my case, the default schema in the early run through DB design was the username (i.e. username.tablename)

Obviously, this has caused problems down the road.

Here’s a fairly simple fix that will work in SQL Server 2005 or SQL Server 2008:
exec sp_MSforeachtable “ALTER SCHEMA newTableSchema TRANSFER ? PRINT ‘? modified’ “

Hope it helps!

Leave a Reply

Powered By Wordpress Designed By Ridgey