Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8088471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:05:56+00:00 2026-06-05T19:05:56+00:00

I’m looking to query all databases mapped to a user, similar to Security >

  • 0

I’m looking to query all databases mapped to a user, similar to Security > Logins > Properties > User Mapping.

This may be done in SQL 2005 if possible

For example, something similar to:

SELECT name
FROM sys.databases
WHERE HAS_DBACCESS(name) = 1

But perform the query from an administrative user, as opposed to running the above query as the user itself.

How would something like this be performed?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:05:58+00:00Added an answer on June 5, 2026 at 7:05 pm

    Well this might be a start, probably not the nice output you’d hope for (and it produces two resultsets):

    EXEC sp_helplogins N'floob';
    

    But it does work on SQL Server 2000. If you want to try and replicate some of the functionality in the procedure, you can see how it’s checking for permissions, basically a cursor through every database. On SQL Server 2000:

    EXEC sp_helptext N'sp_helplogins';
    

    On 2005+ I much prefer the output of OBJECT_DEFINITION():

    SELECT OBJECT_DEFINITION(OBJECT_ID(N'sys.sp_helplogins'));
    

    So you could write your own cursor based on similar logic, and make the output prettier…

    Here is a quick (and not complete) example, doesn’t cover much but an idea to get started if the above is not sufficient:

    DECLARE @login NVARCHAR(255);
    SET @login = N'foobarblat';
    
    -- above would be an input parameter to a procedure, I presume
    
    CREATE TABLE #dbs(name SYSNAME);
    
    DECLARE @sql NVARCHAR(MAX);
    SET @sql = N'';
    
    SELECT @sql = @sql + N'INSERT #dbs SELECT ''' + name + ''' FROM ' 
      + QUOTENAME(name) + '.sys.database_principals AS u
      INNER JOIN sys.server_principals AS l
      ON u.sid = l.sid
      WHERE l.name = @login;'
    FROM sys.databases 
    WHERE state_desc = 'ONLINE'
    AND user_access_desc = 'MULTI_USER';
    
    EXEC sp_executesql @sql, N'@login SYSNAME', @login;
    
    SELECT name FROM #dbs;
    
    DROP TABLE #dbs;
    

    As I said, this is not complete. Won’t know if the user has been denied connect, is member of deny reader/writer roles, won’t show the alias if the user name in the db doesn’t match the login, etc. You can dig into more details from sp_helplogins depending on what you want to show.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.