Execute As Flashcards

1
Q

Why use EXECUTE AS?

A

When you want a user to be able to run a query or stored procedure one time without having to modify the underlying security permanently

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the syntax to EXECUTE AS?

A

EXEC(UTE) AS USER = ‘USERNAME’

REVERT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What if you don’t want the EXECUTE AS statement to end even with a REVERT statement?

A

EXEC AS USER = ‘USERNAME’ WITH NO REVERT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What if you want to specifically revert the EXECUTE AS statement?

A

Use WITH COOKIE:
DECLARE @COOKIE = VARBINARY(8000)
EXEC AS USER = ‘USERNAME’ WITH COOKIE INTO @COOKIE

Then: REVERT WITH COOKIE = @COOKIE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly