Skip to content
  • There are no suggestions because the search field is empty.

T-SQL Script: Identify orphaned users in SQL Database

TSQL - Identify orphaned users in SQL Database

-- Identify orphaned users in SQL Database
 
SELECT dp.name AS OrphanedUser
FROM sys.database_principals dp
LEFT JOIN sys.server_principals sp
  ON dp.sid = sp.sid
WHERE dp.type IN ('S', 'U')  -- SQL or Windows users
  AND sp.sid IS NULL
  AND dp.name NOT IN ('guest', 'dbo', 'INFORMATION_SCHEMA', 'sys');