View All SysAdmins
A query that lists every sysadmin login on the server with its type and dates.
Who has the keys to the kingdom? This query joins sys.server_principals to syslogins and returns every login - SQL, Windows user or Windows group - that has the sysadmin flag set, along with whether it is disabled and when it was created and last modified. It excludes the internal ## process logins.
USE master
GO
SELECT p.name AS [loginname] ,
p.type ,
p.type_desc ,
p.is_disabled,
CONVERT(VARCHAR(10),p.create_date ,101) AS [created],
CONVERT(VARCHAR(10),p.modify_date , 101) AS [update]
FROM sys.server_principals p
JOIN sys.syslogins s ON p.sid = s.sid
WHERE p.type_desc IN ('SQL_LOGIN', 'WINDOWS_LOGIN', 'WINDOWS_GROUP')
-- Logins that are not process logins
AND p.name NOT LIKE '##%'
-- Logins that are sysadmins
AND s.sysadmin = 1
GO