
A few days ago, I conduct an audit to detect all orphan’s windows accounts in a database and I was surprise to have an error during the drop user query. The first step is to find all orphan’s windows accounts in a database USE [dbi_database] GO /*Step1: Search the orphan user */ SELECT * FROM sys.database_principals a LEFT OUTER JOIN sys.server_principals b ON a.sid = b.sid WHERE b.sid IS NULL AND a.type In (‘U’,…