snippetsqlMinor
SQL Server 2008: How do I change the default schema of the dbo?
Viewed 0 times
the2008sqldbodefaulthowserverchangeschema
Problem
When I attempt to change the default schema of the dbo in SQL Server Management Studio, the ALTER fails and states that the dbo account's schema cannot be changed. Are there any tricks that can make is possible to change the the dbo default schema of "dbo" to "xxx"?
Thank you!
Thank you!
Solution
Each database is owned by a server principal (aka login). Inside that database, the owning principal is known as
For example, for a database I own:
Will print "dbo", "Andomar". If you'd change the owner to
The query would return "dbo", "sa".
You cannot modify the default schema for the user that owns a database. It is always user name
dbo (aka DataBase Owner). The database principal (aka user) loses its real name.For example, for a database I own:
select [user].name as UserName -- Database specific
, [login].name as LoginName -- Server wide
from sys.databases d
join sys.database_principals as [user]
on [user].sid = d.owner_sid
join sys.server_principals as [login]
on [login].sid = d.owner_sidWill print "dbo", "Andomar". If you'd change the owner to
sa:exec sp_changedbowner 'sa'The query would return "dbo", "sa".
You cannot modify the default schema for the user that owns a database. It is always user name
dbo with default schema name dbo.Code Snippets
select [user].name as UserName -- Database specific
, [login].name as LoginName -- Server wide
from sys.databases d
join sys.database_principals as [user]
on [user].sid = d.owner_sid
join sys.server_principals as [login]
on [login].sid = d.owner_sidexec sp_changedbowner 'sa'Context
StackExchange Database Administrators Q#6636, answer score: 7
Revisions (0)
No revisions yet.