Why do I (they) own that database?2
February 20, 2019 by Kenneth Fisher
Ever looked at the list of databases and wonder why you own one of them? Or why some other user owns the database? Just to be clear, by owner I mean the one and only actual owner of the database, not just a member of the db_owner role. This can be a bit confusing when you know that you have a policy where the owner of the database is always supposed to be sa (which is also disabled by policy).
No, you didn’t make yourself the owner of the database while you were sleep-working, your co-worker didn’t suddenly go insane and decide they needed to own all of the databases. I’m pretty sure there are other ways this can happen, but every single time I’ve dealt with it, it was a create or a restore.
The owner of a database, until changed, is the person who either created it or the last person to restore it.
So if you or your co-worker did an operational restore and when you (or they) were done, the database now has a new owner. And chances are you (I’m not saying “or they” anymore in this post it’s getting annoying) didn’t think to check who was supposed to own it and change it back when you were done.
Fixing this is simple enough
-- Current command ALTER AUTHORIZATION ON DATABASE::Test TO sa; -- Older command (still works but may go away in the near future) USE Test; EXEC sp_changedbowner 'sa';
I should probably note that the DATABASE:: is required in this case. The class_type isn’t always required on these types of commands, but frequently with the higher level objects (databases for example), it is.
In at least one case I broke things by changing the owner to sa. But I would argue that by using the owner to assign db_owner rights to a user is confusing and asking to be broken.
The only time I’ve seen that break something is when the ID that used to be dbo was used for something. Once it’s no longer dbo it no longer has access to the DB unless you explicitly re-add it.
Beyond that I’m a firm believer that the need for db_owner is a rare and unusual thing. 🙂 Usually DBAs who for whatever reason aren’t allowed to have sysadmin.