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

No feedback yet
Leave a comment

Your email address will not be revealed on this site.
PoorExcellent
(Line breaks become <br />)
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)
Trackback address for this post

http://www.insidesql.org/blogs/htsrv/trackback.php?tb_id=183