How do I create a SQL table under a different schema?

SqlSql Server-2008Ssms

Sql Problem Overview


This is from SQL Server 2008, ssms

When I create a table, it creates under dbo.

I would like to create it under a different schema, but when I use the 'New Table' dialog, I can never find the field where to specify this.

Sql Solutions


Solution 1 - Sql

  1. Right-click on the tables node and choose New Table...
  2. With the table designer open, open the properties window (view -> Properties Window).
  3. You can change the schema that the table will be made in by choosing a schema in the properties window.

Solution 2 - Sql

Try running CREATE TABLE [schemaname].[tableName]; GO;

This assumes the schemaname exists in your database. Please use CREATE SCHEMA [schemaname] if you need to create a schema as well.

EDIT: updated to note SQL Server 11.03 requiring this be the only statement in the batch.

Solution 3 - Sql

                           create a database schema in SQL Server 2008

  1. Navigate to Security > Schemas
  2. Right click on Schemas and select New Schema
  3. Complete the details in the General tab for the new schema. Like, the schema name is "MySchema" and the schema owner is "Admin".
  4. Add users to the schema as required and set their permissions:
  5. Add any extended properties (via the Extended Properties tab)
  6. Click OK.
                               Add a Table to the New Schema "MySchema"
  7. In Object Explorer, right click on the table name and select "Design":
  8. Changing database schema for a table in SQL Server Management Studio
  9. From Design view, press F4 to display the Properties window.
  10. From the Properties window, change the schema to the desired schema:
  11. Close Design View by right clicking the tab and selecting "Close":
  12. Closing Design View
  13. Click "OK" when prompted to save
  14. Your table has now been transferred to the "MySchema" schema.

    Refresh the Object Browser view To confirm the changes
    Done

Solution 4 - Sql

Hit F4 and you'll get what you are looking for.

Solution 5 - Sql

Shaun F's answer will not work if Schema doesn't exist in the DB. If anyone is looking for way to create schema then just execute following script to create schema.

create schema [schema_name]
CREATE TABLE [schema_name].[table_name](
 ...
) ON [PRIMARY]

While adding new table, go to table design mode and press F4 to open property Window and select the schema from dropdown. Default is dbo.

You can also change the schema of the current Table using Property window.

Refer:

enter image description here

Solution 6 - Sql

When I create a table using SSMS 2008, I see 3 panes:

  • The column designer
  • Column properties
  • The table properties

In the table properties pane, there is a field: Schema which allows you to select the schema.

Solution 7 - Sql

The default schema for the user could be changed with the following query and avoids changing the property every time a table is to be created.

USE [DBName] 
GO 
ALTER USER [YourUserName] WITH DEFAULT_SCHEMA = [YourSchema] 
GO

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMattView Question on Stackoverflow
Solution 1 - SqladrianbanksView Answer on Stackoverflow
Solution 2 - SqlShaunView Answer on Stackoverflow
Solution 3 - SqlAftab UddinView Answer on Stackoverflow
Solution 4 - SqlmapView Answer on Stackoverflow
Solution 5 - SqlSangram NandkhileView Answer on Stackoverflow
Solution 6 - SqlBrannonView Answer on Stackoverflow
Solution 7 - SqlNagaraj RaveendranView Answer on Stackoverflow