sql server management history log code example

Example 1: sql server 2012 query history

SELECT t.[text]
FROM sys.dm_exec_cached_plans AS p
CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t
WHERE t.[text] LIKE N'%something unique about your query%';

Example 2: how to check sql server agent job history

-In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.
-Expand SQL Server Agent, and then expand Jobs.
-Right-click a job, and then click View History.
-In the Log File Viewer, view the job history.
-To update the job history, click Refresh.