Hi @Anonymous ,
When you need to review the data about executed SQL statements in SSMS for a particular period, you can use several options:
1.Queries are saved in the cache via system representations (sys.dm_exec_query_stats, sys.dm_exec_sql_text, and sys.dm_exec_query_plan). But this script will only give you recent queries from the cached plan. There is no guarantee that it will be accurate. It is just an indication and helps to do a basic diagnosis of the system. If you remove the plan from the cache, you will not see that row as a result of your query.
2.Using SQL Server Profiler
3.Using Extended Events
4.Using the Query Store, starting from the 2016 version
5.Using SQL Complete (SQL Complete\Execution History) in SSMS
Please refer to the blog How to Check SQL Server Query History to get more information.
I found a similar thread, hope it could help you.
If the response is helpful, please click "Accept Answer" and upvote it, thank you.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.