Changing the schema of a table or view after you have created it in SQL Server

Posted: (EET/GMT+2)

 

Using schemas in SQL Server helps breaking up large databases and can also bring management and security advances. However, if you create tables using SQL Server's own management tool, the SQL Server Management Studio (SSMS), tables are by default created in the all-inclusive "dbo" schema (short for database owner).

I'm not aware of a way you could use the visual management tools to change a table's or view's schema once you have created it in Management Studio, but you can use the ALTER SCHEMA command for this purpose.

This command has the following syntax:

ALTER SCHEMA the-new-schema TRANSFER old-schema.tablename;

Thus, to move a table, say, "dbo.Customers" to the schema "sales", you would execute the following statement:

ALTER SCHEMA sales TRANSFER dbo.Customers;

Hope this helps!