+ Reply to Thread
Results 1 to 2 of 2
  1. Senior Member knownhero's Avatar
    Join Date
    Jul 2008
    Location
    UK
    Posts
    435

    Certifications
    MCSE: SharePoint 2013, Productivity
    #1

    Default TSQL list DB owners

    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
    Code:
    SELECT SUSER_SNAME(owner_sid) from sys.databases
    How do I get it to show me the Databases link with a single account?
    Any help would be great!
    edit:
    Code:
    SELECT DB_NAME(database_id) from sys.databases
    Gives me DB names

    Code:
    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) 
    That doesn't work
    70-410 [x] 70-411 [x] 70-462[x] 70-331[x] 70-332[x]
    MCSE - SharePoint 2013

    Road map 2017: JavaScript and modern web development

    Reply With Quote Quote  

  2. Senior Member knownhero's Avatar
    Join Date
    Jul 2008
    Location
    UK
    Posts
    435

    Certifications
    MCSE: SharePoint 2013, Productivity
    #2
    Figured it out in the end. I was looking at it completely wrong!

    Code:
    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

    Road map 2017: JavaScript and modern web development

    Reply With Quote Quote  

+ Reply to Thread

Social Networking & Bookmarks