Table creation in non dbo schema

   I work with Sql server 2016 . While creating a table it is getting created in the DBO schama and I have no option to change . How can I create a table in a different schema?
Sam OZAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Give this a whirl..
-- Create schema new_schema if it does not already exist
IF (NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'new_schema')) 

-- Move your_table to schema new_schema
ALTER SCHEMA new_schema TRANSFER dbo.your_table

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nitin SontakkeDeveloperCommented:
Or while creating table itself, which is I guess what you are asking for...

create table [schema_name].[table_name]
  -- column definition goes here...

Open in new window

Vitor MontalvãoMSSQL Senior EngineerCommented:
When creating an object in SQL Server, the object will be created in the default user schema if no explicit schema has been provided.
To create an object in a different database schema you'll need to explicitly say the schema name, as provided above by Nitin. Mind that the user need to have permissions to create objects in the desired schema.
You also have to create the schema first.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.