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

Database Security /* Q9. Assuming you are currently working on a query editing p

ID: 3712991 • Letter: D

Question

Database Security

/* 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

SOLUTION:-

Let I am already connected with Rony as user1

CREATE USER assistant FOR LOGIN monty;

GO

--setting permissions on assistant to Rony

--so that user1 will set the execution context to assistant

GRANT IMPERSONATE ON USER:: assistant TO Rony;

GO

--Test the execution context is now Rony.

SELECT SUSER_NAME(), USER_NAME();

--Rony will transfers the execution context to monty (that will work for user assistant)

EXECUTE AS USER = 'assistant';

--Display the present execution context.

SELECT SUSER_NAME(), USER_NAME();

--The REVERT statement will change the execution context from the 'assistant' user back to Rony(user1)

REVERT;

--Displaying the present execution context.

SELECT SUSER_NAME(), USER_NAME();

===================================================================================