execute as

CREATE PROCEDURE dbo.usp_Demo

WITH EXECUTE AS ‘SqlUser1’

AS

SELECT user_name(); — Shows execution context is set to SqlUser1.

EXECUTE AS CALLER;

SELECT user_name(); — Shows execution context is set to SqlUser2, the caller of the module.

REVERT;

SELECT user_name(); — Shows execution context is set to SqlUser1.

GO

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.