SQL Server SYSTEM_USER Function

The SYSTEM_USER function in SQL Server provides a way to identify the currently connected user. It returns the login name of the user who is currently interacting with the database.



SYSTEM_USER: Definition and Usage

This function is particularly useful for security and auditing purposes. You can use it within your SQL code to determine who is performing database operations or accessing data. The returned value represents the login name of the user, not necessarily the database user name.

Syntax

The syntax is incredibly simple; it doesn't take any arguments:

Syntax

SYSTEM_USER
      

Example

Retrieving the Current User's Login Name

The following query retrieves the login name of the user currently connected to the SQL Server instance.

Syntax

SELECT SYSTEM_USER;
      
Output

YourLoginNameHere (Replace with your actual login name)
      

Technical Details

The SYSTEM_USER function is available in:

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