SUSER_NAME (Transact-SQL)

Applies to: SQL Server Azure SQL Managed Instance Azure Synapse Analytics (serverless SQL pool only)

Returns the login identification name of the user.

Transact-SQL syntax conventions

Syntax

SUSER_NAME ( [ server_user_id ] )

Note

To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.

Arguments

server_user_id

The login identification number of the user. server_user_id, which is optional, is int. server_user_id can be the login identification number of any SQL Server login or Windows user or group that has permission to connect to an instance of SQL Server. When server_user_id isn't specified, the login identification name for the current user is returned. If the parameter contains the word NULL, it will return NULL.

Return type

nvarchar(128)

Remarks

SUSER_NAME returns a login name only for a login that has an entry in the syslogins system table.

SUSER_NAME can be used in a select list, in a WHERE clause, and anywhere an expression is allowed. Use parentheses after SUSER_NAME, even if no parameter is specified.

Note

Although the SUSER_NAME function is supported on Azure SQL Database, using EXECUTE AS with SUSER_NAME is not supported on Azure SQL Database.

Examples

The following example returns the login identification name of the user with a login identification number of 1.

SELECT SUSER_NAME(1);

See also