Get list of all database users with specified role

前端 未结 4 1579
情书的邮戳
情书的邮戳 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条回答
  •  长情又很酷
    2021-01-01 12:09

    In SQL 2005 and 2008 this information is most easily accessed in two catalog views.

    This query should give you the information you're looking for.

    select rp.name as database_role, mp.name as database_user
    from sys.database_role_members drm
    join sys.database_principals rp on (drm.role_principal_id = rp.principal_id)
    join sys.database_principals mp on (drm.member_principal_id = mp.principal_id)
    

提交回复
热议问题