You can use TRANSFER keyword to change the SCHEMA name of your table in Sql Server.
If you have created your table in wrong schema or you want to move your existing table to another schema in SQL, you can perform this ALTER using TRANSFER command.
Let's create a table in schema DBO and try to move it in another schema.
Create a table EMPLOYEE_DETAIL in schema [DBO].
--Create table EMPLOYEE_DETAIL in schema DBO. This is default schema
CREATE TABLE [DBO].[EMPLOYEE_DETAIL](
ID INT IDENTITY(1,1) PRIMARY KEY,
NAME VARCHAR(50),
ADDRESS VARCHAR(250),
ISACTIVE BIT NOT NULL DEFAULT(1),
[DATE] DATETIME NOT NULL DEFAULT(GETDATE())
)
Create a new EMPLOYEE schema.
You can create new schema using CREATE SCHEMA SCHEMA_NAME command.
--Create Schema EMPLOYEE
CREATE SCHEMA EMPLOYEE
To change table schema use alter command with transfer keyword.
Use ALTER SCHEMA [NEW_SCHEMA] TRANSFER [OLD_SCHEMA].[TABLE_NAME] to change schema name of table.
--Move EMPLOYEE_DETAIL table from schema [DBO] to [EMPLOYEE]
ALTER SCHEMA EMPLOYEE
TRANSFER [DBO].[EMPLOYEE_DETAIL]
Table is successfully moved from schema [DBO] to new schema [EMPLOYEE]. Hope this help you.