DECLARE @name VARCHAR(50) -- database name CREATE TABLE #temprr(RoleName nvarchar(max),MemberName nvarchar(max), LoginType nvarchar(max)) DECLARE db_cursor CURSOR FOR SELECT name FROM sys.databases OPEN db_cursor FETCH NEXT FROM db_cursor INTO @name WHILE @@FETCH_STATUS= 0 BEGIN PRINT @name INSERT INTO #temprr EXEC('USE ['+ @name +']; select rp.name as RoleName, mp.name as MemberName, mp.type_desc as Type from sys.database_role_members drm join sys.database_principals rp on (drm.role_principal_id = rp.principal_id) join sys.database_principals mp on (drm.member_principal_id = mp.principal_id)') FETCH NEXT FROM db_cursor INTO @name END CLOSE db_cursor DEALLOCATE db_cursor SELECT * FROM #temprr where MemberName notlike'NT%'and MemberName notlike'##%'
order by MemberName drop table #temprr;
MvM
No comments:
Post a Comment