Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to current logged windows user name in tsql?


Asked by Bo Buckley on Dec 13, 2021 Windows



In my application we had created special login through all users are accessing sql server from diffrent terminals i want read particualr terminals name suppose 'John' inserted some rows then how can determine that who had inserted rows. I think the answer is: you can't (exactly).
Similarly,
Get current logged in user name command line (CMD) In Windows OS, we can find the current logged in username from windows command line. The logged in user information is stored in environment variables. So just by printing the value in these environment variables we can get to know the login name.
Furthermore, When USER_NAME is called without specifying an id after an EXECUTE AS statement, USER_NAME returns the name of the impersonated user. If a Windows principal accesses the database by way of membership in a group, USER_NAME returns the name of the Windows principal instead of the group.
Moreover,
There is no link between a SQL login and the NT username. The WMI approach will be ambiguous if more than 1 user is logged into the client PC (eg service accounts, remote user via mstsc etc). Any approach like this will require admin rights on the client PC too for the account used.
Accordingly,
How to see who is Logged on Windows 10 1 Press the Windows logo key + R simultaneously to open the Run box. Type cmd and press Enter. 2 When the Command Prompt window opens, type query user and press Enter. It will list all users that are currently logged on your computer. See More....