sp_helpuser (Transact-SQL)

 

Reports information about database-level principals in the current database.

System_CAPS_ICON_important.jpg Important


sp_helpuser does not return information about securables that were introduced in SQL Server 2005. Use sys.database_principals instead.

Applies to: SQL Server (SQL Server 2008 through current version).

Topic link icon Transact-SQL Syntax Conventions

  
sp_helpuser [ [ @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 must exist in the current database. security_account is sysname, with a default of NULL. If security_account is not specified, sp_helpuser returns information about all database principals.

0 (success) or 1 (failure)

The following table shows the result set when neither a user account nor a SQL Server or Windows user is specified for security_account.

Column nameData typeDescription
UserNamesysnameUsers in the current database.
RoleNamesysnameRoles to which UserName belongs.
LoginNamesysnameLogin of UserName.
DefDBNamesysnameDefault database of UserName.
DefSchemaNamesysnameDefault schema of the database user.
UserIDsmallintID of UserName in the current database.
SIDsmallintUser 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 nameData typeDescription
LoginNamesysnameLogins aliased to users in the current database.
UserNameAliasedTosysnameUser name in the current database to which the login is aliased.

The following table shows the result set when a role is specified for security_account.

Column nameData typeDescription
Role_namesysnameName of the role in the current database.
Role_idsmallintRole ID for the role in the current database.
Users_in_rolesysnameMember of the role in the current database.
UseridsmallintUser ID for the member of the role.

To see information about membership of database roles, use sys.database_role_members. To see information about server role members, use sys.server_role_members, and to see information about server-level principals, use sys.server_principals.

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. For more information, see Metadata Visibility Configuration.

A. Listing all users

The following example lists all users in the current database.

EXEC sp_helpuser;  

B. Listing information for a single user

The following example lists information about the user database owner (dbo).

EXEC sp_helpuser 'dbo';  

C. Listing information for a database role

The following example lists information about the db_securityadmin fixed database role.

EXEC sp_helpuser 'db_securityadmin';  

Security Stored Procedures (Transact-SQL)
System Stored Procedures (Transact-SQL)
Principals (Database Engine)
sys.database_principals (Transact-SQL)
sys.database_role_members (Transact-SQL)
sys.server_principals (Transact-SQL)
sys.server_role_members (Transact-SQL)

Community Additions

ADD
Show: