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
1.4m articles
1.4m replys
5 comments
57.0k users