Get list of all database users with specified role

前端 未结 4 1575
情书的邮戳
情书的邮戳 2021-01-01 11:44

I want to get list of all database users with specified role. Role is a parameter for stored procedure or function.

Somethinf like a select statement with user name

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-01 12:22

    just depending on how you want to pass the parameter...assuming you'll use the id of the role

    declare @roleID int
    
    select
        role_principal_id as roleID, 
        user_name(role_principal_id) as roleName, 
        member_principal_id as memberID,
        user_name(member_principal_id) as memberName 
    from 
        sys.database_role_members
    where 
        role_principal_id = @roleID
    

提交回复
热议问题