List Orphan ID’s

This script displays the list of orphan SQL Server accounts from all the databases. This script is applicable for version greater than SQL 2000.


EXEC SP_MSForEachDB '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'

Sample Output

DBName UserName UserSID
MSDB_TEST TestUser 0x3BD4F53355FF874A9E923735DBF1F5B1

Leave a Reply

Leave a comment

Your email address will not be published. Required fields are marked *