The below SQL query is useful to find out the Security Roles assigned to the users from backend by querying the Organization_MSCRM database in SQL Server.
select role.name as 'Role Name',
cast(systemuser.systemuserid as nvarchar(50)) as 'System User Id',
fullname as 'Full Name',
domainname as 'Domain Name',
firstname as 'First Name',
lastname as 'Last Name',
internalemailaddress as 'Mail ID',
isdisabledname as 'Status',systemuser.businessunitidname as 'Business Unit', systemuser.businessunitid as 'Business Unit ID'
from Filteredsystemuser AS systemuser
LEFT JOIN FilteredSystemUserRoles AS userroles on systemuser.systemuserid = userroles.systemuserid
LEFT JOIN FilteredRole AS role on role.roleid = userroles.roleid
where domainname is not null
This shall return only the roles which are directly associated to the user. slightly modified the query to retrieve the role which are inherited by the team membership.
This returns the same output of Xrm.Page.context.getUserRoles()
INNER JOIN FilteredTeamMembership AS teammember on teammember.systemuserid=systemuser.systemuserid
INNER JOIN FilteredTeamRoles AS teamroles on teamroles.teamid=teammember.teamid
INNER JOIN FilteredRole AS role on role.roleid = teamroles.roleid
order by domainname