SQL CURRENT_USER() Function: Complete Guide

SQL CURRENT_USER function returns the name of the current user in the SQL Server database.

SQL CURRENT_USER()

SQL CURRENT_USER() is a built-in function that returns the name of a current user in the SQL Server database. MySQL CURRENT_USER function returns the user name and hostname for the MySQL account.

Syntax

CURRENT_USER;

Parameters

There are no parameters and arguments for the CURRENT_USER function.

Note

Parentheses may or may not be used after the CURRENT_USER function.

Works on

It works on the 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.

Example

SELECT CURRENT_USER;

Output

‘dbadmin’

Explanation

The CURRENT_USER function returned the name of the current user from the existing database.

The CURRENT_USER returns the name of the current security context. If CURRENT_USER executes after a call to EXECUTE AS switches context, CURRENT_USER will return the name of the impersonated context.

If a Windows principal accessed the database by way of membership in a group, CURRENT_USER would return the name of the Windows principal instead of the group name.

Finally, SQL CURRENT_USER() Function Example is over.

See also

SQL SESSION_USER

SQL SYSTEM_USER

SQL USER_NAME

Leave a Comment

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