How to find loginname, database username, or roles of sqlserver domain user who doesn't have their own login?

Posted by Adam Butler on Stack Overflow See other posts from Stack Overflow or by Adam Butler
Published on 2010-11-24T14:54:14Z Indexed on 2012/09/30 21:38 UTC
Read the original article Hit count: 279

I have created a login and database user called "MYDOMAIN\Domain Users". I need to find what roles a logged on domain user has but all the calls to get the current user return the domain username eg. "MYDOMAIN\username" not the database username eg. "MYDOMAIN\Domain Users".

For example, this query returns "MYDOMAIN\username"

select original_login(),suser_name(), suser_sname(), system_user, session_user,  current_user, user_name()

And this query returns 0

select USER_ID()

I want the username to query database_role_members is there any fuction that will return it or any other way I can get the current users roles?

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about sql-server-2008