Why would you ever use EXECUTE AS CALLER?

  • Since it is the default, I don't understand what the point of this option would be.

  • It would only be required if you've changed user context earlier. The example from books online:

    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

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply