Query below shows queries executed in specific time range.
Table containing query log retain them approximately for 2-5 days then they are removed.
Query below lists queries executed between 6 and 12 hours from current time.
select usename as username, database, querytxt as query, starttime, endtime, case aborted when 1 then 'YES' else 'NO' end as aborted from stl_query ql join svl_user_info us on ql.userid = us.usesysid where starttime < DATEADD(hour, -6, getdate()) and starttime > DATEADD(hour, -12, getdate()) order by starttime desc;
- username - name of user who executed query
- database - name of database in which query was executed
- query - query text
- starttime - start time of a query
- endtime - end time of a query
- aborted - indicate wheter query was aborted
- One row represents one query executed in specifiic time range
- Scope of rows: all queries executed in specifiic time range
- Ordered by start time of query