Orphan SQL-Server accounts

By

Posted on Apr 18, 2008 by in SQL Server

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

This entry was posted by and is filed under SQL Server. Tags: sp_msforeachdb, t-sql

No feedback yet


Form is loading...