SQL Server allows a login with sufficient rights to issue a setuser
command and impersonate another user. For e.g I can connect as user1 and if I have syadmin role, I can issue a setuser 'user2'
. Now my context gets switched to user2.
But is there any way to figure out that, using T-SQL:
I think you want the function ORIGINAL_LOGIN(). Also, I think you'll find sys.sysprocesses.loginame remains constant no matter what happens with setuser
or execute as
.