EXECUTE ... AS { LOGIN | USER }
runs the string under another principal
What changes
- Input
- principal name
- Output or change
- execution context for the dynamic statement
Syntax at a glance
EXEC ( ... ) AS { LOGIN | USER } = 'name'
Work example
A controlled module must run under a reviewed database or login security context.
Test the context switch with a nonprivileged account. Define the REVERT path before the context change begins.
Check your work EXECUTE ... AS { LOGIN | USER }. The module sees only the approved permissions and the caller context is restored on every exit path.
Open Microsoft Learn for full syntax, permissions, and details for your version.