Orphan SQL-Server accounts

By using SP_MSForEachDB you can detect and display orphan SQL-Server accounts from all the databases of your SQL-Server.


EXEC SP_MSForEachDB 'USE [?];
        -- SYSTEM DATABASE ARE EXCLUDED
        IF DB_ID(''?'') > 4
	SELECT ''?'' as DBName,
	name AS UserName, 
	sid  AS UserSID 
	FROM .sysusers 
	WHERE issqluser = 1 AND
	(
	sid IS NOT NULL AND sid <> 0x0
	) 
	AND suser_sname(sid) IS NULL
	ORDER BY name'

CU tosc