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.

Script

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

Posted

in

by

Comments

Leave a Reply

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