19

When creating tables in SSMS, I've realized that if you execute the following statement:

CREATE TABLE [tableName];

the table will be created under your own schema (and not dbo). So in order to create it under the dbo schema, you'll need to explicitly say so, like this:

CREATE TABLE [dbo].[tableName];

Does anyone know of a way (eg. server-wide setting) so that when a table is created, the [dbo] part doesn't need to be specified?

Chinesinho
  • 611
  • 2
  • 8
  • 15

2 Answers2

10

The schema that will be used when schema is omitted will be the default schema of the database user. Therefore, to have dbo schema have the created table without specifying, you'd have to set that database user's default schema to dbo.

Server-wide setting? I don't think so. But you could write a query to convert all database users in a particular database to their default schema changed to dbo if that's what you so choose.

Thomas Stringer
  • 42,224
  • 9
  • 117
  • 154
9

Maybe this can help

USE [YourDBName]
GO
ALTER USER [YourUserName] WITH DEFAULT_SCHEMA=[dbo]
GO
Mike A
  • 103
  • 2
  • 3
    but if user is in windows Authentication then it cannot set the default schema –  Oct 11 '13 at 04:05