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
2,049 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
[X]
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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

735 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