Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/* Q9. Assuming you are currently working on a query editing page or session of

ID: 3711471 • Letter: #

Question

/* Q9.
Assuming you are currently working on a query editing page or session of Clearwater database
in your SQL Server using your own login, what statement do you need to execute in order to
switch the execution context from yours to the 'assistant' user, that is, pretending you are
the 'assistant' user of Clearwater? What statement is needed to switch the execution context
back to your own?
*/

--To switch the execution context from yours to the 'assistant' user:

--To switch the execution context from the 'assistant' user back to your own:

Explanation / Answer

1. To switch the execution context from yours to the 'assistant' user: this can be done with the help of 'Execute As' statement. When we run this statement , the execution context of the session will be switched to the specified user name. But credentials for the new user have to be checked. If that doesnt match context switching can not be done. Database Engine uses to validate permissions on objects that are referenced by the module.

To specify EXECUTE AS on a database user, the caller must have IMPERSONATE permissions on the specified user name.

2. To switch the execution context from the 'assistant' user back to your own: REVERT can be used to switch back to original account.

Revert; will reset the execution context to the previous context user.

REVERT statement can be used multiple times to move up to stack until the execution context is set to the original caller.