Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question
1  
Which version of SQL server? –  KAJ Mar 2 '12 at 18:15
4  
And why do you have a problem with explicitly specifying? –  HLGEM Mar 2 '12 at 18:40
    
add comment

migrated from stackoverflow.com Mar 2 '12 at 18:55

This question came from our site for professional and enthusiast programmers.

2 Answers

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.

share|improve this answer
    
@KAJ: SQL2008R2 –  Chinesinho Mar 2 '12 at 18:21
1  
But you can't set the default schema to dbo for Windows groups... –  Chinesinho Mar 2 '12 at 18:21
2  
@Chinesinho You can't set the default schema of any server principal. You're confusing server logins and database users. Database users contain default schemas. –  Thomas Stringer Mar 2 '12 at 19:29
    
Setting the default schema for users mapped to Windows group logins isn't supported prior to SQL Server 2012. –  db2 Oct 11 '13 at 14:31
add comment

May be this can help

USE [YourDBName]
GO
ALTER USER [YourUserName] WITH DEFAULT_SCHEMA=[DBO]
GO
share|improve this answer
    
but if user is in windows Authentication then it cannot set the default schema –  user29261 Oct 11 '13 at 4:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.