Step by Step guide to know Logged in User Information
Hello everyone, this is Mayank Sanghvi from Vlemon.com, and I welcome you all in another Step-by-Step guide. In it, we will learn How to know logged-in user information. Sometimes we need to track logged-in user activity and find the logged-in user information. If we use SQL Server Management Studio, we can find the logged-in user information under the Object explorer or Status bar at the bottom.
We can execute the following T-SQL statement if we need to find the logged-in user information.
SELECT SESSION_USER LoggedInUser
The above queries work. But let us switch to the “master” database and execute the same T-SQL query again.
This time it did not work. “guest” is the wrong user. The current user is “ZeroTutorialDemo.”
We have an alternate. Let us try the following query.
SELECT SESSION_USER SessionUser , SUSER_NAME() LoggedInUser
SUSER_NAME() is more reliable compared with SESSION_USER.
The same query will also work with Windows Authentication.
We would love to know what you used and the above query’s purpose.
Leave A Comment