Got a question today. How do I tell what user my sql server query is running as? Well you just ask.
Using the USER_NAME() function, without passing it an id, finds the name of the current user.
Using the SUSER_NAME() function, gets me the login identification name of the user.
Here is an example of each, using both a regular sql server login (left) and windows authentication (right)
Now that I know who I am, why not be someone else. . . In this example I change the context that I am running under with the “EXECUTE AS LOGIN” statement, then I revert back using . . . wait for it. . . the “REVERT” statement.
EXECUTE AS: http://msdn.microsoft.com/en-us/library/ms181362.aspx
and they say getting to know ones self is hard. . .