Returns a user database username from a given identification number.
USER_NAME([id])
nchar
When id is omitted, the current user is assumed. Parentheses are required.
This example returns the username for user number 13.
SELECT USER_NAME(13)
GO
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)
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)
ALTER TABLE | Modifying Column Properties |
CREATE TABLE | SESSION_USER |
CURRENT_TIMESTAMP | SYSTEM_USER |
CURRENT_USER | System Functions |