USER_NAME

Transact-SQL Reference

Transact-SQL Reference

USER_NAME

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

nvarchar(256)

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

CREATE TABLE

CURRENT_TIMESTAMP

CURRENT_USER

Modifying Column Properties

SESSION_USER

System Functions

SYSTEM_USER