USER_NAME (TSQL Function)

Returns the name of the user or role with the specified ID in the current database.

Syntax

USER_NAME ( [principal_id] )

Arguments

principal_id
optional argument, ID of a user or role, of type bigint. If omitted, the name of the current user in the current database is returned.

Return Types

Returns varchar.

Remarks

Returns NULL if the user or role doesn’t exist in the current database.

The functions SESSION_USER, CURRENT_USER, USER and USER_NAME() return the same result.

Examples

PRINT SESSION_USER;
PRINT CURRENT_USER;
PRINT USER;
PRINT USER_NAME();
PRINT USER_NAME(30071);

The result is:

john
john
john
john
fred