sp_helpuser (Transact-SQL)sp_helpuser (Transact-SQL)

适用对象: 是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

报告有关当前数据库中数据库级主体的信息。Reports information about database-level principals in the current database.

重要

sp_helpuser不返回有关在中引入的安全对象的信息SQL Server 2005 (9.x)SQL Server 2005 (9.x)sp_helpuser does not return information about securables that were introduced in SQL Server 2005 (9.x)SQL Server 2005 (9.x). 使用sys.database_principals相反。Use sys.database_principals instead.

主题链接图标 TRANSACT-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

  
sp_helpuser [ [ @name_in_db = ] 'security_account' ]  

参数Arguments

[ @name_in_db = ] 'security_account' 是数据库用户或当前数据库中的数据库角色的名称。[ @name_in_db = ] 'security_account' Is the name of database user or database role in the current database. security_account必须存在于当前数据库。security_account must exist in the current database. security_accountsysname,默认值为 NULL。security_account is sysname, with a default of NULL. 如果security_account未指定,则sp_helpuser返回有关所有数据库主体的信息。If security_account is not specified, sp_helpuser returns information about all database principals.

返回代码值Return Code Values

0(成功)或 1(失败)0 (success) or 1 (failure)

结果集Result Sets

下表显示了结果集当没有用户帐户也不是SQL ServerSQL Server为指定 Windows 用户或security_accountThe following table shows the result set when neither a user account nor a SQL ServerSQL Server or Windows user is specified for security_account.

列名Column name 数据类型Data type 描述Description
UserNameUserName sysnamesysname 当前数据库中的用户。Users in the current database.
RoleNameRoleName sysnamesysname 角色所属用户名所属。Roles to which UserName belongs.
LoginNameLoginName sysnamesysname 登录名用户名Login of UserName.
DefDBNameDefDBName sysnamesysname 默认数据库用户名Default database of UserName.
DefSchemaNameDefSchemaName sysnamesysname 数据库用户的默认架构。Default schema of the database user.
UserIDUserID smallintsmallint ID用户名当前数据库中。ID of UserName in the current database.
SIDSID smallintsmallint 用户的安全标识号 (SID)。User security identification number (SID).

下表显示未指定用户帐户,并且当前数据库中存在别名时的结果集。The following table shows the result set when no user account is specified and aliases exist in the current database.

列名Column name 数据类型Data type 描述Description
LoginNameLoginName sysnamesysname 当前数据库中已经化名为用户名的登录名。Logins aliased to users in the current database.
UserNameAliasedToUserNameAliasedTo sysnamesysname 当前数据库中登录名要化名为的用户名。User name in the current database to which the login is aliased.

下表显示了结果集时为指定角色security_accountThe following table shows the result set when a role is specified for security_account.

列名Column name 数据类型Data type 描述Description
Role_nameRole_name sysnamesysname 当前数据库中角色的名称。Name of the role in the current database.
Role_idRole_id smallintsmallint 当前数据库中角色的角色 ID。Role ID for the role in the current database.
Users_in_roleUsers_in_role sysnamesysname 当前数据库中角色的成员。Member of the role in the current database.
用户 IdUserid smallintsmallint 角色的成员的用户 ID。User ID for the member of the role.

备注Remarks

若要查看数据库角色的成员身份的信息,请使用sys.database_role_membersTo see information about membership of database roles, use sys.database_role_members. 若要查看有关服务器角色成员的信息,请使用sys.server_role_members,若要查看有关服务器级别主体的信息,请使用sys.server_principalsTo see information about server role members, use sys.server_role_members, and to see information about server-level principals, use sys.server_principals.

权限Permissions

要求 公共 角色具有成员身份。Requires membership in the public role.

返回的信息取决于对元数据的访问权限的限制。Information returned is subject to restrictions on access to metadata. 主体对其不具有权限的实体将不会显示。Entities on which the principal has no permission do not appear. 有关详细信息,请参阅 Metadata Visibility ConfigurationFor more information, see Metadata Visibility Configuration.

示例Examples

A.A. 列出所有用户Listing all users

以下示例列出当前数据库中的所有用户。The following example lists all users in the current database.

EXEC sp_helpuser;  

B.B. 列出单个用户的信息Listing information for a single user

以下示例列出有关用户数据库所有者 (dbo) 的信息。The following example lists information about the user database owner (dbo).

EXEC sp_helpuser 'dbo';  

C.C. 列出某个数据库角色的信息Listing information for a database role

以下示例列出有关 db_securityadmin 固定数据库角色的信息。The following example lists information about the db_securityadmin fixed database role.

EXEC sp_helpuser 'db_securityadmin';  

请参阅See Also

安全存储过程 (Transact-SQL) Security Stored Procedures (Transact-SQL)
系统存储过程 (Transact-SQL) System Stored Procedures (Transact-SQL)
主体(数据库引擎) Principals (Database Engine)
sys.database_principals (Transact-SQL) sys.database_principals (Transact-SQL)
sys.database_role_members (Transact-SQL) sys.database_role_members (Transact-SQL)
sys.server_principals (Transact-SQL) sys.server_principals (Transact-SQL)
sys.server_role_members (Transact-SQL)sys.server_role_members (Transact-SQL)