SQL Server: SYSTEM_USER Function

SYSTEM_USER function in SQL Servers

This SQL Server tutorial explains how to use the SYSTEM_USER function in SQL Servers (Transact-SQL) with syntax and examples.

Description

In SQL Server (Transact-SQL), the SYSTEM_USER functions returns the login name information for the current user in the SQL Server database.

Syntax

The syntax for the SYSTEM_USER function in SQL Server (Transact-SQL) is:

SYSTEM_USER

Parameters or Arguments

There are no parameters or arguments for the SYSTEM_USER function.

Note

  • If the current user is logged into SQL Server using Windows Authentication, the SYSTEM_USER function will return the login name information in the following format: DOMAIN\user_name
  • If the current user is logged into SQL Server using SQL Server Authenication, the SYSTEM_USER function will return the login name information in the following format: user_name
  • Do not put parentheses () after the SYSTEM_USER function.
  • See also the CURRENT_USERUSER_NAME, and SESSION_USER functions.

Applies To

The SYSTEM_USER function can be used in the following versions of SQL Server (Transact-SQL):

  • SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

Example

Let’s look at some SQL Server SYSTEM_USER function examples and explore how to use the SYSTEM_USER function in SQL Server (Transact-SQL).

For example:

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

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

This Post Has One Comment

Leave a Reply