I want to move a table into a specific Schema using T-SQL? I am using SQL Server 2008.
ALTER SCHEMA TargetSchema TRANSFER SourceSchema.TableName;
If you want to move all tables into a new schema, you can use the undocumented (and to be deprecated at some point, but unlikely!) sp_MSforeachtable stored procedure:
sp_MSforeachtable
exec sp_MSforeachtable "ALTER SCHEMA TargetSchema TRANSFER ?"
Ref.: ALTER SCHEMA
ALTER SCHEMA
SQL 2008: How do I change db schema to dbo
2.1m questions
2.1m answers
60 comments
57.0k users