Thursday, September 14, 2017

Get Last executed Query in SQL Server

SELECT
    equery.last_execution_time AS [Time],
    esql.TEXT AS [Query]
 FROM
    sys.dm_exec_query_stats AS equery
    CROSS APPLY sys.dm_exec_sql_text(equery.sql_handle) AS esql
WHERE esql.dbid = DB_ID('DatabasName')
ORDER BY
    equery.last_execution_time DESC

No comments:

Post a Comment

Disabling the flight in D365FO (CHD - Tier 1)

 INSERT INTO dbo.SYSFLIGHTING(FLIGHTNAME, ENABLED)  VALUES ('<FlightObjectName>_KillSwitch', 1)  or  INSERT INTO dbo.SYSFLIGHT...