I'm trying to better understand why one of our database update scripts failed to work properly at a particular customer site, and narrowed it down (I think) to database ownership and roles.
Disclaimer: I'm actually waiting to hear back from the customer's DBA so they can tell us if they upgraded their SQL database recently and so we can look at their database. I'm thinking a SQL 2000 to SQL 2005 conversion might have hosed our scripts if our applications's database login was converted to a schema, because we were referencing
dbo
in a few places in the update script.
Anyway, I've been trying to find a better explanation of database ownership and roles and how it impacts what owner a database object is actually assigned when you don't explicitly specify the owner in a T-SQL statement. For example, our update scripts typically just do CREATE TABLE foo
instead of CREATE TABLE dbo.foo
or something else, but I found a few that were explicitly using dbo
, and those are the ones causing problems at the moment (only for this one customer).
I found this article (specific to SQL Server 2000), but the table on that page is confusing. It mentions db_owner
and "owns the database" as two distinct possibilities for what role a user can have.
For example, the table states that if a user sam
, who is in the db_owner
role, runs the query CREATE TABLE [test3](abc int)
, it will be owned by sam
.
It then mentions that if a another user sue
, who "owns the database" (sic), runs the same query, it will be owned by dbo
.
Wouldn't db_owner
and "owns the database" be the same thing? The table implies that there is a difference between "being in the db_owner
role" and actually "being the owner of the database." But, if that's, true, what does it mean to "own the database" if it's something other than being a member of the db_owner
role?