SQL Server CURRENT_USER Function

The CURRENT_USER function in SQL Server is a simple yet powerful way to identify the currently connected user within your database.



CURRENT_USER: Definition and Usage

This function returns the database user name associated with the current session. It's a crucial function for security and auditing purposes. You can use it to determine who is making changes to your database.

Syntax

The syntax is incredibly straightforward:

Syntax

CURRENT_USER
      

Example

Retrieving the Current User

The following query demonstrates how to use CURRENT_USER to get the name of the connected user.

Syntax

SELECT CURRENT_USER;
      
Output

YourUserNameHere  (Replace with your actual username)
      

Technical Details

CURRENT_USER works in:

  • SQL Server (starting with version 2008)
  • Azure SQL Database
  • Azure SQL Data Warehouse
  • Parallel Data Warehouse