SQL Server how to run as another user?

EXECUTE AS LOGIN = ‘login1’;
–Verify the execution context is now login1.
SELECT SUSER_NAME(), USER_NAME();
–Login1 sets the execution context to login2.
EXECUTE AS USER = ‘user2’;
–Display current execution context.
SELECT SUSER_NAME(), USER_NAME();
— The execution context stack now has three principals: the originating caller, login1 and login2.
–The following REVERT statements will reset the execution context to the previous context.
REVERT;

Leave a Reply

Your email address will not be published. Required fields are marked *