Explicit Context Switching

With explicit context switching, you can use the EXECUTE AS statement to change the user or login used to check permissions. This is similar to the SET USER statement available in SQL Server 2000 and SQL Server 2005. It is extremely useful for administrators who are testing the permissions they have set for users or logins. The following example demonstrates the use of the explicit EXECUTE AS statement:

image

You can also do explicit context switching at the login level. You can use the EXECUTE AS statement to switch the execution context to another login instead of a user.

Context switching is linked to the IMPERSONATE

Get Microsoft® SQL Server 2008 R2 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.