AppDividend
Latest Code Tutorials

SQL SESSION_USER Function Example

0

SQL SESSION_USER is an inbuilt function that is used for returning the name of the user working currently in the SQL SERVER database. SQL SESSION_USER returns the user name of the current context in the current database.

SQL SESSION_USER

MySQL SESSION_USER function returns the current user name and hostname for the MySQL connection. The SESSION_USER() function returns the current username and hostname for the MySQL connection. The SESSION_USER() function is equal to the SYSTEM_USER() and the USER() function.

Syntax

SESSIOIN_USER;

Parameters

There are no parameters and arguments for SESSION_USER function.

Note

Parentheses may or may not be used after the SESSION_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 SESSION_USER;

Output

‘Rohik’

Explanation

Here, right now, Rohik named person was executing the task in SQL SERVER DATABASE. So, the SESSION_USER function returned the name of the working user from an existing database.

Use SESSION_USER with DEFAULT constraints in either the CREATE TABLE or ALTER TABLE statements, or use it as any standard function. SESSION_USER can be inserted into a table when no default value is specified. The SESSION_USER function takes no arguments. SESSION_USER can be used in queries.

If SESSION_USER is called after the context switch, the SESSION_USER will return the user name of the impersonated context.

See also

SQL SYSTEM_USER

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.