This SQL Server tutorial explains how to use the USER_NAME function in SQL Server (Transact-SQL) with syntax and examples.
Description
In SQL Server (Transact-SQL), the USER_NAME function returns the user name in the SQL Server database.
Syntax
The syntax for the USER_NAME function in SQL Servers (Transact-SQL) is:
USER_NAME( [ identification_number ] )
Parameters or Arguments
identification_number
Optional. The identification number associated with a user in SQL Server.
Note
- If the identification_number is specified, the USER_NAME function will return the user name for that identification_number.
- If the identification_number is not provided, the USER_NAME function will return the current user in SQL Servers in the given context.
- See also the CURRENT_USER, SESSION_USER, SYSTEM_USER functions.
Applies To
The USER_NAME functions can be used in the following versions of SQL Server (Transact-SQL):
- SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005
Example
Let’s look at some SQL Server USER_NAME function examples and explore how to use the USER_NAME function in SQL Servers (Transact-SQL).
For example:
SELECT USER_NAME(); Result: 'dbo' SELECT USER_NAME(12); Result: 'jsmith'
Pingback: SQL Server: CURRENT_USER function - Adglob Infosystem Pvt Ltd
I really liked your blog post. Really Cool.