Question : DB Owner right is missing but I can't find which database it is

I have MS SQL 2008 environment. There are several SQL users and they are having public and dbowner rights to specific databases. In this SQL there are about 5000 databases. One user doesn’t have dbowner right to some of his database. The problem is that this user has around 1500 databases and this is too much to check it manually. These 1500 databases are in alphabetical order (first one is c4001_lat and last one is c4375_mat).
Can someone help me to write a query which will check that from which database (or databases) this dbowner right is missing?

Thank you :)

Answer : DB Owner right is missing but I can't find which database it is

you specified that database name has some pattern so give db name with like, for eg:


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
exec sp_MSforeachdb
'Use ?
if not  exists (
SELECT
1
FROM
sys.database_role_members  RoleMem
JOIN sys.database_principals RolePri ON  RoleMem.role_principal_id = RolePri.principal_id
JOIN  sys.database_principals MemPri ON RoleMem.member_principal_id =  MemPri.principal_id
where Mempri.name=''riteshshah'')  and ''?'' like ''ad%''

select  ''?''
'
--My database is starting with AD so ad%..... you can have your own pattern.
Random Solutions  
 
programming4us programming4us