Using Security Directory Views , you can get basic information about the database and server, for example:
USE [database_name] SELECT sp.name AS login_name FROM sys.server_principals sp JOIN sys.database_principals dp ON (sp.sid = dp.sid) WHERE dp.name = 'user_name'
I canβt find a view that will give you all users, regardless of the database, so this needs to be run in the context of the login database.
source share