TSQL list DB owners

knownheroknownhero Member Posts: 450
Just have a question on T-SQL for finding all databases owner by a certain user. I can just get that information via user mappings but I really want to expand my query knowledge so here goes.

So far I have managed to piece together a query that shows me the users on all databases
[B]SELECT SUSER_SNAME(owner_sid) from sys.databases[/B]

How do I get it to show me the Databases link with a single account?
Any help would be great!
edit:
[B]SELECT DB_NAME(database_id) from sys.databases[/B]
Gives me DB names
[B]SELECT DB_NAME(database_id)AS dbname FROM sys.databases 
  WHERE SUSER_SNAME(owner_sid) IN (SELECT SUSER_SNAME(owner_sid)AS dbuser FROM sys.databases) [/B]

That doesn't work icon_sad.gif
70-410 [x] 70-411 [x] 70-462[x] 70-331[x] 70-332[x]
MCSE - SharePoint 2013 :thumbup:

Road map 2017: JavaScript and modern web development

Comments

  • knownheroknownhero Member Posts: 450
    Figured it out in the end. I was looking at it completely wrong!
    SELECT name from sys.databases where SUSER_SNAME(owner_sid) = 'YourUsername'
    
    70-410 [x] 70-411 [x] 70-462[x] 70-331[x] 70-332[x]
    MCSE - SharePoint 2013 :thumbup:

    Road map 2017: JavaScript and modern web development

Sign In or Register to comment.