Retrieve the database user name associated with the current user (typically returns the current user when no specific ID is specified).
| SELECT USER_NAME(); |
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.
| USER_NAME(id_number) |
|
Parameter |
Description |
|
id_number |
Optional. The numeric identifier of a user in the database. |
|
Works in: |
SQL Server (from 2008 onward), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse |
Retrieve the database user name associated with the user ID 1.
| SELECT USER_NAME(1); |