USER_NAME
security context lookup
What changes
- Input
- security context (login, user, roles, permissions)
- Output or change
- name, id or boolean
- Return type
- nvarchar(128)
Syntax at a glance
USER_NAME ( [ ID ] )
Work example
Resolve a database principal id to its database user name.
Test under the intended execution context. Use GRANT and DENY rather than returned identity text.
Check your work Principal ids are database-local and can be hidden by metadata visibility.
Open Microsoft Learn for full syntax, permissions, and details for your version.