Solved

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
5
1,773 Views
Last Modified: 2012-05-05
Hi,
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.
0
Comment
Question by:patel99
  • 3
5 Comments
 
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

0
 
LVL 32

Accepted Solution

by:
bhess1 earned 125 total points
ID: 22769418
This code should provide you with the base of what you need:
CREATE TABLE #tmp (

	UserName Sysname NULL,

	groupName Sysname NULL,

	loginName Sysname NULL,

	DefDBName Sysname NULL,

	defSchema Sysname NULL,

	userID Sysname NULL,

	sid Sysname NULL

	)
 

INSERT INTO #tmp

EXECUTE sp_helpuser
 

SELECT *

FROM #tmp t

WHERE groupName = 'db_datareader'
 

DROP TABLE #tmp 

Open in new window

0
 

Author Comment

by:patel99
ID: 22772704
Thanks....bhess1 and DanielWilson......
0
 

Author Comment

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

Author Closing Comment

by:patel99
ID: 31508142
Thanks a lot.....
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

21 Experts available now in Live!

Get 1:1 Help Now