How can I get list of users having DB_datareader or DB_datawriter permission among all users having different permission in SQL 2005 ?

Posted on 2008-10-20
Last Modified: 2012-05-05
I want to find out list of users having db_datareader or any other permission in Database. In my database there are about 200 users some of them have DB_datareader permission and some of them DB_data executor and DB_datawriter....How can I find out list of users having different permission.
Question by:patel99
  • 3
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22769248
how's this?

Select P.Name, P.type_desc, R.Name as RoleName 

from sys.database_principals P Inner Join 

 sys.database_role_members M on P.Principal_ID = M.member_principal_ID Inner Join

 sys.database_principals R on R.Principal_ID = M.role_principal_ID

Open in new window

LVL 32

Accepted Solution

bhess1 earned 125 total points
ID: 22769418
This code should provide you with the base of what you need:

	UserName Sysname NULL,

	groupName Sysname NULL,

	loginName Sysname NULL,

	DefDBName Sysname NULL,

	defSchema Sysname NULL,

	userID Sysname NULL,

	sid Sysname NULL



EXECUTE sp_helpuser


FROM #tmp t

WHERE groupName = 'db_datareader'


Open in new window


Author Comment

ID: 22772704
Thanks....bhess1 and DanielWilson......

Author Comment

ID: 22772715
I found....
exec sp_helprolemember 'db_datareader'     is working as well.

Author Closing Comment

ID: 31508142
Thanks a lot.....

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create a linked  server to connect ot an Access Database. 26 46
SQL Select * from 6 36
Not selecting duplicate data 6 42
ms sql + top 1 for each customer 3 43
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate ( First, just open a new email message. In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now