SQL SYSTEM_USER() Function: Complete Guide

0
1
SQL SYSTEM_USER() Function Example

If you are using a MySQL database, The SYSTEM_USER() function returns the current user name and hostname for the MySQL connection.

SQL SYSTEM_USER()

SQL SYSTEM_USER() is a built-in function used to return the login information for the current user in the SQL SERVER or MySQL database. The SYSTEM_USER() function returns the login name information for the current user.

If the user name and login name differ, the SYSTEM_USER() returns the login name. You can use the SYSTEM_USER with DEFAULT constraints in the CREATE TABLE and ALTER TABLE statements.

Syntax

SYSTEM_USER;

Parameters

There are no parameters and arguments for the SYSTEM_USER function.

Note

  1. If the user is logged into the database using Windows authentication, then the output will be in the following format: DOMAIN/user_name.
  2. If the user is logged into the Database using SQL Server authentication, then the output will be in the following format: user_name.
  3. Parentheses may or may not be used after the SYSTEM_USER() function.

Work On

It works on following SQL SERVER.

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

Query 1

SELECT SYSTEM_USER;

Output

‘Ankit’

Explanation

The SYSTEM_USER function returned the login information of the current user logged into the Database using SQL SERVER AUTHENTICATION.

Query 2

SELECT SYSTEM_USER;

Output

‘Domain_name\Ankit’

Explanation

The SYSTEM_USER function returned the login information of the current user logged into the Database using WINDOWS AUTHENTICATION.

See also

SQL Insert Query

SQL Insert Multiple Rows

SQL Char Function

Leave A Reply

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.