SQL SYSTEM_USER

The SYSTEM_USER function in SQL returns the name of the current system user connected to the database. This function is useful for tracking which user is executing a query, ensuring database security, and maintaining audit logs.

In this tutorial, we will explore the SYSTEM_USER function, its syntax, and practical examples to understand its usage.


Syntax of SQL SYSTEM_USER

The SYSTEM_USER function does not require any parameters and can be used as follows:

</>
Copy
SELECT SYSTEM_USER;

Explanation:

  • SYSTEM_USER retrieves the name of the current database user executing the query.
  • It returns a system-defined username that represents the login identity.

Step-by-Step Examples Using SQL SYSTEM_USER

1 Checking the Current System User

Let’s find the login identity of the user connected to the database.

</>
Copy
SELECT SYSTEM_USER AS current_user_1;

Output (example):