Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Roles 2

Status
Not open for further replies.

reena72

Programmer
Apr 18, 2001
3
US
Hi,
I need to get the roles assigned to a user in all the databases that the user exists in.
Does someone have a script to do that?


Thanks a lot,
Reena
 
Hi, will this help you?

SELECT b.name as UserName, a.name as Role
FROM sysusers b, sysusers a, sysmembers m
WHERE a.uid = m.groupuid AND b.uid = m.memberuid

Andel
andelbarroga@hotmail.com
 
This is similar to the query proposed by Andel but allows you to search by login rather than user. That would help if the login name differs from the user name in the database.

declare @lname varchar(40) /* the login name */
set @lname='loginname'

select
DbRole = cast(g.name As varchar(30)),
MemberName = cast(u.name As varchar(30))

from master..syslogins l
join sysusers u on l.suid=u.suid
join sysmembers m on u.uid=m.memberuid
join sysusers g on m.groupuid=g.uid

where l.name=@lname
and g.issqlrole=1
Terry
 
Hi everyone
Thanks for the replies.
Terry, when I ran your query, there are no results displayed. Not sure whatz wrong with it. Thanks again for replying.

Regards,
Renate
 
My query was not finding logins that were users in a database but had not been assigned a role other than 'Public.' 'Public' is the default role.

This new query will find users in any assigned roles as well as the 'Public' role. It will also indicate if the login is not a user in the database or if the login doesn't exist on the server.

Hope you get better results. Terry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top