Returns the name within the database of the specified user or of the current user.
user_name([user_id])
is the ID of a user.
select user_name()
------------------------------ dbo
select user_name(4)
------------------------------ margaret
user_name, a system function, returns the user’s name, based on the user’s ID in the current database. For general information about system functions, see “System functions”.
If no user_id is supplied, user_name returns the name of the current user.
If the sa_role is active, you are automatically the Database Owner in any database you are using. Inside a database, the user_name of the Database Owner is always “dbo”.
SQL92 – Compliance level: Transact-SQL extension.
You must be a System Administrator or System Security Officer to use this function on a user_id other than your own.
Functions suser_name, user_id