SQL Server Tip: How to find the owner of a database through T-SQL
This weekend, I was trying to do just this and after scowering Google, I was quite surprised not to find any blog posts or articles addressing this. So here is my little tidbit and my hope Google picks this up so others trying to do the same thing will find out how quick and easy.
Basically, I needed a way to get the name of a database's owner through a regular SQL command. After trying numberous Google searches, I came up empty. Then I tried running SQL Profiler while loading up the properties for a database to capture which query that data was returned in, but it was so chatty it was impossible to find. So finally, I dived into some of the system tables and T-SQL commands and found what I needed. Not too hard to figure out, but I was surprised Google didn't return anything (I thought Google was all knowing!).
So here you go:
select suser_sname(owner_sid) from sys.databases
Or want just a specific database?
select suser_sname(owner_sid) from sys.databases where name = 'Northwind'
Hopefully now others will be able to find out how quickly and easily.