Displaying mapping between sql_logins and database_principals

display name 1 Reputation point
2022-02-17T00:03:59.373+00:00

How can this be done?

The documentation describes a function which appears to not exist. sp_helplogins is described here: https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/security-stored-procedures-transact-sql?view=azuresqldb-current

Running the below statement within master as server admin result in the error message:
SQL Error [2812] [S0062]: Could not find stored procedure 'sp_helplogins'.

The statement (without quotes): "EXEC sp_helplogins;"

I'd like a single-query approach to identify which users are assigned to each sql_login.

Thanks

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Alberto Morillo 33,611 Reputation points MVP
    2022-02-17T01:00:47.537+00:00

    As you can verify here sp_helplogin can be found on SQL Server instances biut not on Azure SQL instances.

    To find the login (master database) mapped to a database user, look at the sid column from sys.sysusers on the user database (not in the master). This value corresponds to the sid column from sys.sql_logins in the master database.

    Unfortunately, you cannot discover the login name for the SID while connected to the user database. You must connect separately to the master database once you have the sid and query sys.sql_logins to get the name.

    Here you will find another way to do the mapping between logins and database users.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.