AppDividend
Latest Code Tutorials

SQL SYSTEM_USER() Function Example

0

SQL SYSTEM_USER() is an inbuilt function that is used for returning the login information for the current user in the SQL SERVER or MySQL database. It returns the login name information for the current user. For the MySQL database, The SYSTEM_USER() function returns the current user name and hostname for the MySQL connection.

SQL SYSTEM_USER()

If the user name and login name are different, 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 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 Database using WINDOWS AUTHENTICATION.

See also

SQL Insert Query

SQL Insert Multiple Rows

SQL Char Function

Leave A Reply

Your email address will not be published.

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