Search code examples
sql-serversql-server-2008-r2schemacreate-tableowner

Set dbo as default schema for all new tables


I have a database installed on four different production servers. Each server has its own different user. When I create a new table using create statement on these servers every server sets / prepends their user name e.g.

Create Table tab_1 ... will be created as
abc.tab_1 on server_1 using abc as login
def.tab_1 on server_2 using def as login
ghi.tab_1 on server_3 using ghi as login
jkl.tab_1 on server_4 using jkl as login

I want to use dbo as default schema and have to use following statement on every server for every new table

ALTER SCHEMA dbo TRANSFER login.table_name;

Is there any way to modify Create Table statement or other setting by which every table is created on all servers as dbo.table_name

I am using shared hosting and there are many restrictions in SSMS, so a query based solution would be appropriate.


Solution

  • You have control over the create table queries? In that case simply specify dbo in create:

    CREATE TABLE dbo.dummy ();

    For changing default schema for a user see this answer: https://stackoverflow.com/a/8208124/3480246