SQL Tutorial SQL Advanced SQL Database SQL References

SQL Server SYSTEM_USER Function



The SQL Server (Transact-SQL) SYSTEM_USER function returns the login name information for the current user in the SQL Server database.

If the current user is logged in to SQL Server by using Windows Authentication, SYSTEM_USER returns the Windows login identification name in the form: DOMAIN\user_name. However, if the current user is logged in to SQL Server by using SQL Server Authentication, SYSTEM_USER returns the SQL Server login identification name in the following format: user_name.

Syntax

SYSTEM_USER

Parameters

No parameter is required.

Return Value

Returns the login name information for the current user in the SQL Server database.

Example:

The example below shows the usage of SYSTEM_USER function.

--logged in using Windows Authentication
SELECT SYSTEM_USER;
Result: 'test_domain\jsmith' 

--logged in using SQL Server Authentication
SELECT SYSTEM_USER;
Result: 'jsmith' 

❮ SQL Server Functions