SQL Server: Get database name

5 pts.
Tags:
Database
SQL Server
How do I get the database name and associated user mapped for all database in SQL Server?


Software/Hardware used:
monitoring
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

if you are a developer then obviously your name/id will be the user and database name is usually in the code at the top of a stored procedure or table script.

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Subhendu Sen
    It can be possible by t-sql script or powershell script. If you want to map for current databse only,
    use master
    go 
    exec sp_mslogingmappings 'sa', 0
    141,290 pointsBadges:
    report
  • danieljones
    To get the current database name use 
    DB_NAME ( [ database_id ] )

    Try fn_my_permissions. It will list all the users mappings with database roles
    EXECUTE AS USER = 'username';
    SELECT * FROM fn_my_permissions(NULL, 'DATABASE')  

    2,840 pointsBadges:
    report
  • Elizine
    You can the database name for all databases in SQL Server using Transact-SQL.
    https://msdn.microsoft.com/en-us/library/ms189753.aspx
    1,145 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: