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
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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.