0% found this document useful (0 votes)
4 views

SQL Server USER_NAME() Function

The SQL Server USER_NAME() function retrieves the database user name based on a specified id, returning the current user if no id is provided. The syntax for the function is USER_NAME(id_number), where id_number is optional. This function is compatible with SQL Server starting from 2008 and other Azure SQL services.

Uploaded by

soha.adel66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

SQL Server USER_NAME() Function

The SQL Server USER_NAME() function retrieves the database user name based on a specified id, returning the current user if no id is provided. The syntax for the function is USER_NAME(id_number), where id_number is optional. This function is compatible with SQL Server starting from 2008 and other Azure SQL services.

Uploaded by

soha.adel66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1/22/25, 6:02 PM SQL Server USER_NAME() Function

 Tutorials  Exercises  Certificates  Services  Search...  Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

SQL Server USER_NAME() Function


❮ Previous ❮ SQL Server Functions Next ❯

Example Get your own SQL Server

Return the database user name (will return the current user since no id is specified):

SELECT USER_NAME();

Try it Yourself »

Definition and Usage


The USER_NAME() function returns the database user name based on the specified id.

https://www.w3schools.com/sql/func_sqlserver_user_name.asp 1/8
1/22/25, 6:02 PM SQL Server USER_NAME() Function

If no id is specified, this function will return the name of the current user.
 Tutorials  Exercises  Certificates  Services   Sign Up Log in

 Syntax
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

USER_NAME(id_number)

Parameter Values
Parameter Description

id_number Optional. The id number of a user in the database

Technical Details
Works in: SQL Server (starting with 2008), Azure SQL Database, Azure SQL Data Warehouse,
Parallel Data Warehouse

More Examples

Example
Return the database user name with id 1:

SELECT USER_NAME(1);

https://www.w3schools.com/sql/func_sqlserver_user_name.asp 2/8
1/22/25, 6:02 PM SQL Server USER_NAME() Function

Try it Yourself »
Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

❮ Previous ❮ SQL Server Functions Next ❯

Track your progress - it's free! Sign Up Log in

ADVERTISEMENT

https://www.w3schools.com/sql/func_sqlserver_user_name.asp 3/8
1/22/25, 6:02 PM SQL Server USER_NAME() Function

 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

https://www.w3schools.com/sql/func_sqlserver_user_name.asp 4/8
1/22/25, 6:02 PM SQL Server USER_NAME() Function

 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

COLOR PICKER



ADVERTISEMENT ADVERTISEMENT

https://www.w3schools.com/sql/func_sqlserver_user_name.asp 5/8
1/22/25, 6:02 PM SQL Server USER_NAME() Function

 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

 PLUS SPACES GET CERTIFIED FOR TEACHERS

FOR BUSINESS CONTACT US

Top Tutorials Top References


HTML Tutorial HTML Reference
CSS Tutorial CSS Reference
JavaScript Tutorial JavaScript Reference
How To Tutorial SQL Reference
SQL Tutorial Python Reference
Python Tutorial W3.CSS Reference
W3.CSS Tutorial Bootstrap Reference
Bootstrap Tutorial PHP Reference
PHP Tutorial HTML Colors
Java Tutorial Java Reference

https://www.w3schools.com/sql/func_sqlserver_user_name.asp 6/8
1/22/25, 6:02 PM SQL Server USER_NAME() Function
C++ Tutorial Angular Reference

 Tutorials jQuery Tutorial


Exercises 
Top Examples
Certificates  jQuery Reference
Services 
Get Certified
 Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R
HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate

    

FORUM ABOUT ACADEMY


W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy
policy.

https://www.w3schools.com/sql/func_sqlserver_user_name.asp 7/8
1/22/25, 6:02 PM SQL Server USER_NAME() Function
Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

https://www.w3schools.com/sql/func_sqlserver_user_name.asp 8/8

You might also like