Created
May 13, 2022 14:19
-
-
Save Otterpohl/75ad458d13419a550b2158acdd42c1c1 to your computer and use it in GitHub Desktop.
Gets users who have been orphaned
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT dp.name AS [user_name], | |
dp.type_desc AS [user_type], | |
ISNULL(sp.name, 'Orphaned!') AS [login_name], | |
sp.type_desc AS [login_type] | |
FROM sys.database_principals AS dp | |
LEFT JOIN sys.server_principals AS sp | |
ON (dp.sid = sp.sid) | |
WHERE dp.type IN ( 'S', 'U', 'G' ) | |
AND dp.principal_id > 4 | |
ORDER BY sp.name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment