Is there a way to obtain user who ran a query if I have the sql_handle, query_hash, plan_handle, query_plan_hash? Could I use any of these data points to find out the user who ran the query?
Asked
Active
Viewed 456 times
1 Answers
4
No. Query plans are shared across sessions, and by default there's no historical record of which sessions ran which queries.
You can capture this data with Audit or Extended Events.
David Browne - Microsoft
- 46,306
- 3
- 46
- 96
dboand the objects are in thedboschema, user_id in that DMV will be 1, the user_id ofdbo. As the plan can be reused by any user whose default_schema isdbo. – David Browne - Microsoft Aug 10 '21 at 15:11