Move tables between schemas : schema « User Role « SQL Server / T-SQL Tutorial






9> CREATE SCHEMA Sales
10> GO
1>
2> CREATE SCHEMA Purchases
3> GO
1>
2>
3> --Create a table in the schema
4> CREATE TABLE Sales.SalesData
5> (
6>     SaleNumber INT,
7>     SaleDate DATETIME
8> )
9> GO
1>
2>
3> --Move the SalesData table into the new schema
4> ALTER SCHEMA Purchases
5> TRANSFER Sales.SalesData
6> GO
1>
2> --Reference the table by its new schema name
3> SELECT *
4> FROM Purchases.SalesData
5> GO
SaleNumber  SaleDate
----------- -----------------------

(0 rows affected)
1>
2> drop table Purchases.SalesData
3> drop SCHEMA Purchases;
4> drop SCHEMA Sales;
5> GO








28.10.schema
28.10.1.Create a new schema
28.10.2.Move tables between schemas
28.10.3.Reference the schema in a query