DBA > Job Interview Questions > Microsoft SQL Server FAQs

SELECT USER_NAME() -- Returns Andy

More DBA job interview questions and answers at http://dba.fyicenter.com/Interview-Questions/

(Continued from previous question...)

SELECT USER_NAME() -- Returns Andy

What does this return?
SELECT USER_NAME() -- Returns Andy
EXECUTE AS Brian
GO
EXECUTE AS Steve
GO
REVERT
GO
SELECT USER_NAME()


Answer
Brian

Explanation
The execution context switches can be nested, so changing to Brian, then Steve, then issuing a Revert will return you to the context of Brian. This works in the same manner as a stack.

(Continued on next question...)

Other Job Interview Questions