如何查询 SQL Server 2000 数据库中的数据库角色列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14143115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:56:10  来源:igfitidea点击:

How can I query the list of database roles in a SQL Server 2000 database?

sqlsql-server-2000sql-server-administration

提问by Warrior Bob

In Sql Server 2000, is it possible to return, via SQL query, a complete list of database roles that exist in a given database?

在 Sql Server 2000 中,是否可以通过 SQL 查询返回给定数据库中存在的数据库角色的完整列表?

I know it is possible to see these roles by expanding the Security, Roles, and Database Roles nodes in SQL Server Management Studio, but I'd like to get them through a query that I can parse programmatically.

我知道可以通过扩展 SQL Server Management Studio 中的安全、角色和数据库角色节点来查看这些角色,但我想通过我可以以编程方式解析的查询来获取它们。

Screenshot of the nodes in question

相关节点的屏幕截图

To clarify, I'm not looking for a list of users with their roles, but just the list of roles themselves.

澄清一下,我不是在寻找具有角色的用户列表,而只是在寻找角色本身的列表。

回答by Laurence

Every database in SQL Server 2000 has a sysusers system table

SQL Server 2000 中的每个数据库都有一个sysusers 系统表

Probably something like

大概是这样的

Use <MyDatabase>

Select 
  [name]
From
  sysusers
Where
  issqlrole = 1

will do the trick

会做的伎俩

回答by Brian H Wilson

With our SQL Server 2016 this works for me

使用我们的 SQL Server 2016 这对我有用

Use Sandbox
Select
  name, principal_id
From
  sys.database_principals 
Where
  type = 'R' and principal < 16384

where Sandbox is the name of my database. (I'm using SQL with ESRI ArcGIS Enterprise 10.6.)

其中 Sandbox 是我的数据库的名称。(我在 ESRI ArcGIS Enterprise 10.6 中使用 SQL。)