SQL Server enables you to check last query executed by each session. Queries in this article will show you how to do it.
Find a session
First you need to identify session. Find out more here:
Result shows three sessions from host LS-MICHALWROBEL:
Find last query
Now we will use session ID (spid) to find last query issued in this session:
dbcc inputbuffer(<session ID>)
- EventType - event type. RPC Event means procedure call. Language Event means sql query.
- Parameters - number of query parameters.
- EventInfo - last statement in session. Returns only first 4000 characters.
We can see that last query issued insession 67 was "select * from mytable"