Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

USER_NAME

Example

Retrieve the database user name associated with the current user (typically returns the current user when no specific ID is specified).

SELECT USER_NAME();

Definition and Usage

The USER_NAME() function retrieves the database user name corresponding to a specified ID.

If no ID is provided, it returns the name of the current user.

Syntax

USER_NAME(id_number)

Parameter Values

Parameter

Description

id_number

Optional. The numeric identifier of a user in the database.

Technical Details

Works in:

 SQL Server (from 2008 onward), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse

More Examples

Example

Retrieve the database user name associated with the user ID 1.

SELECT USER_NAME(1);