capture who executes view

Winston TheFifth 101 Reputation points

How do you capture who is executing a view? By knowing who executed the view I can implement role based security to manage what they're able to see.

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,513 questions
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 98,751 Reputation points

    There are a couple of options, and which to use depends on how your application connects to SQL Server.

    But to keep things simple: the one you want in the plain-vanilla case is SYSTEM_USER:


    This returns the current login. To confuse matter there is also SESSION_USER, suser_sname() and maybe some which I have forgotten. They are entirely equivalent.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Ronen Ariely 15,081 Reputation points


    In order to catch event you should use "Extended events"

    For more information you can start here: Quickstart: Extended events in SQL Server

    0 comments No comments

  2. 2022-06-26T23:42:41.333+00:00

    You can
    Continue with us will be the solution

    0 comments No comments