Wednesday, June 20, 2018

Query to list each SQL Server database with owner

Just a quick one.  I've advised a customer of the complications of using domain logins for database owners, and they've agreed to change the owner to sa for all databases where necessary.  So, in prep for said change, I wrote a quick query to list all databases with owners, so I could see which ones required changed.  This statement will return back your databases w/owners for quick review.


-- list databases w/owners 
SELECT
       name [Database],
       suser_sname(owner_sid) [Owner]
FROM
       sys.databases
WHERE
       database_id > 4


Should return something for you a little like this: