Sql-server – Steal ownership on database from user that no longer exists

permissionssql-server-2008-r2

We have a few SQL Server 2008 R2 databases where its member domain was changed (i.e. it was connected to DOMAINA and is now on DOMAINB). We have three databases where the owner of the database is DOMAINA\User, which no longer exists.

I have tried logging on to SQL Server as DOMAINB\Administrator and sa and run the following command:

ALTER AUTHORIZATION ON DestDB TO sa

Error:

Msg 15151, Level 16, State 1, Line 1
Cannot find the object 'DestDB', because it does not exist or you do not have permission.

I was under the (obviously incorrect) assumption that sa could do virtually anything on the server.

How can I get ownership of these databases back?

Best Answer

The syntax you're using is attempting to change ownership of the object 'DestDB' within whatever database context you're currently in. You need to specify that you're changing database ownership by using the class definition:

ALTER AUTHORIZATION ON DATABASE::[DestDB] TO [sa]