Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Brendt Hess earned 375 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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

704 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