SQL CURRENT_USER Function Example
SQL CURRENT_USER is an inbuilt function that is used for returning the name of the current user in the SQL SERVER database. SQL CURRENT_USER function returns the name of the current user in the SQL Server database.
SQL CURRENT_USER
SQL CURRENT_USER function 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 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.