USER_NAME (T-SQL)

Returns a user database username from a given identification number.

Syntax

USER_NAME([id])

Arguments
id
Is the identification number used to return a user’s name. id is int.
Return Types

nchar

Remarks

When id is omitted, the current user is assumed. Parentheses are required.

Examples
A. Use USER_NAME

This example returns the username for user number 13.

SELECT USER_NAME(13)

GO

B. Use USER_NAME without an ID

This example finds the name of the current user without specifying an ID.

SELECT user_name()

GO

  

Here is the result set (for a user who is a member of the sysadmin fixed server role):

------------------------------

dbo                           

  

(1 row(s) affected)

  

C. Use USER_NAME in the WHERE clause

This example finds the row in sysusers in which the name is equal to the result of applying the system function USER_NAME to user identification number 1.

SELECT name

FROM sysusers

WHERE name = USER_NAME(1)

GO

  

Here is the result set:

name                          

------------------------------

dbo                           

  

(1 row(s) affected)

  

See Also
ALTER TABLE Modifying Column Properties
CREATE TABLE SESSION_USER
CURRENT_TIMESTAMP SYSTEM_USER
CURRENT_USER System Functions


(c) 1988-98 Microsoft Corporation. All Rights Reserved.