SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Why do I (they) own that database?

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
-- 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.


My name is Kenneth Fisher and I am Senior DBA for a large (multi-national) insurance company. I have been working with databases for over 20 years starting with Clarion and Foxpro. I’ve been working with SQL Server for 12 years but have only really started “studying” the subject for the last 3. I don’t have any real "specialities" but I enjoy trouble shooting and teaching. Thus far I’ve earned by MCITP Database Administrator 2008, MCTS Database Administrator 2005, and MCTS Database Developer 2008. I’m currently studying for my MCITP Database Developer 2008 and should start in on the 2012 exams next year. My blog is at www.sqlstudies.com.


Leave a comment on the original post [sqlstudies.com, opens in a new window]

Loading comments...