You can use system stored procedure sp_msloginmappings to list out the SQL logins and database user mappings.
Syntax
sp_msloginmappings @Loginname , @Flags
@Loginname – Optional argument, in case if you not specify the Login name procedure will return the result for all the SQL Server logins
@Flags – You can specify value 0 or 1, 0 value will show user mapping to all databases and 1 will show the user mapping to current database only. Default value is 0
use master go exec sp_msloginmappings 'sa', 0use master go exec sp_msloginmappings 'sa', 1In case you want to run the sp_msloginmappings across multiple SQL Instance using either Central management server or powershell. You can use the below script.
create table #loginmappings( LoginName nvarchar(128) NULL, DBName nvarchar(128) NULL, UserName nvarchar(128) NULL, AliasName nvarchar(128) NULL ) insert into #loginmappings EXEC master..sp_msloginmappings select * from #loginmappings drop table #loginmappings
Before you hand an AI agent a login, run this
This script answers the first question every AI deployment has to answer: what can this identity actually touch? Before an agent, a service account, or a RAG pipeline gets a login, map its database user mappings with sp_msloginmappings and confirm least privilege — no mapping, no access. Identity is the “I” in my AI risk framework: trusted data access, least privilege, auditability. The framework: R-I-S-K-S: The 5-Dimension Framework for AI Risk Management


Thanks for the comment, will get back to you soon... Jugal Shah