SQL: Determining the Windows Groups for a SQL Server Login
I saw a question on a SQL Server mailing list about how to determine the Windows groups for a given SQL Server login.
That’s actually easy for a sysadmin login, as they have IMPERSONATE permission for other logins/users.
Here is an example procedure:
USE tempdb;
GO
CREATE OR ALTER PROCEDURE dbo.GetGroupsForALogin
@LoginName sysname
AS
BEGIN
EXECUTE AS Login = @LoginName;
SELECT [name] AS GroupName,
usage AS Usage
FROM sys.login_token
WHERE [type] = N'WINDOWS GROUP';
END;
GO
When I executed this on one of my SQL Server 2025 systems this way:
2026-06-03