Sql-server – Change the owner of an offline database without bringing it online

sql server

If it is possible I would like to know how to do it via Sql Server Management Studio.

When a database is online I can do it in the files option of the db properties. I don't see that option when the database is offline.

I'm using SQL Server 2008 R2.

Best Answer

This can't be done without bringing the database online, and this is not just a GUI problem.

ALTER AUTHORIZATION ON DATABASE::test TO sa;

Yields:

Msg 942, Level 14, State 4, Line 1
Database 'test' cannot be opened because it is offline.

So, as one of the comments suggested, bring it online, set it to single_user if you need to, change the owner, then take it back offline.

ALTER DATABASE test SET ONLINE;
ALTER DATABASE test SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER AUTHORIZATION ON DATABASE::test TO sa;
ALTER DATABASE test SET MULTI_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE test SET OFFLINE WITH ROLLBACK IMMEDIATE;

Though I have to wonder, why do you care who the owner is until you've brought the database online?