最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sql server - Role member to view other role members - Stack Overflow

programmeradmin0浏览0评论

Is this even possible?

I tried with grants to the role. I tried with views but nothing works. sp_getrolemember is no longer available in SQL Server 2022.

Is there a way to make normal role members view other role members in the same database without giving them additional powers?

Is this even possible?

I tried with grants to the role. I tried with views but nothing works. sp_getrolemember is no longer available in SQL Server 2022.

Is there a way to make normal role members view other role members in the same database without giving them additional powers?

Share Improve this question edited Nov 20, 2024 at 19:40 Dale K 27.5k15 gold badges58 silver badges83 bronze badges asked Nov 20, 2024 at 11:43 user763539user763539 3,7199 gold badges49 silver badges106 bronze badges 1
  • To see data in sys.database_principles for others the USER needs the ALTER ANY USER or ALTER ANY ROLE permissions respectively for users and roles. – Thom A Commented Nov 20, 2024 at 12:06
Add a comment  | 

2 Answers 2

Reset to default 0

You could re-create sp_getrolemember with your own stored procedure. Here is how:

  1. Create a table of members, roles and types:
    CREATE PROCEDURE dbo.GetRoleMembers
    @RoleName NVARCHAR(128)
    AS
    BEGIN
        SELECT 
            r.name AS RoleName,
            u.name AS MemberName,
            u.type_desc AS MemberType
        FROM 
            sys.database_role_members rm
        INNER JOIN 
            sys.database_principals r ON rm.role_principal_id = r.principal_id
        INNER JOIN 
            sys.database_principals u ON rm.member_principal_id = u.principal_id
        WHERE 
            r.name = @RoleName;
    END;
  1. Let's say you want only 'mary' to access this. You can remove public access: DENY EXECUTE ON dbo.GetRoleMembers TO PUBLIC;

  2. Grant view permissions to mary: GRANT EXECUTE ON dbo.GetRoleMembers TO Mary;

Lmk if that helps!

You must grant them View on the database.

发布评论

评论列表(0)

  1. 暂无评论