Monday, July 23, 2007

Which Roles Does The User Belong To?

SELECT r.[name] Role_Name FROM sys.database_principals u
JOIN sys.database_role_members rm ON u.principal_id = rm.member_principal_id
JOIN sys.database_principals r ON rm.role_principal_id = r.principal_id
WHERE u.[name] = USER_NAME()

1 Comments:

At 10:23 AM, Blogger Alex Kuznetsov (MVP) said...

If I add a login to a role it works. Unfortunately this does not work when a user is a member of NT group which is added to a role.

 

Post a Comment

<< Home