Permalink
Browse files

Add method to get execution count and last execution date for each st…

…ored procedure
  • Loading branch information...
gboge committed Oct 18, 2017
1 parent 8d6e13b commit cf750c3e551b162eac4f64d3905d29b073130221
Showing with 17 additions and 0 deletions.
  1. +17 −0 KDatabase.cs
View
@@ -433,6 +433,23 @@ UNION all
DROP TABLE #TEMP").Tables[0];
}
public static DataTable GetLastExecutionByProcedure(this smo.Database d)
{
return d.ExecuteWithResults(@"SELECT sc.name AS [Schema]
, p.name AS [Procedure Name]
, SUM(execution_count) AS [Execution Count]
, MAX (last_execution_time) AS [Last Execution Time]
FROM sys.procedures p
INNER JOIN sys.schemas sc ON p.schema_id = sc.schema_id
LEFT JOIN sys.dm_exec_procedure_stats s ON sc.name = OBJECT_SCHEMA_NAME(s.object_id, database_id)
AND p.name = OBJECT_NAME(s.object_id, database_id)
AND s.database_id = DB_ID()
GROUP BY sc.name
, p.name
ORDER BY sc.name
, p.name").Tables[0];
}
/// <summary>
/// Find all columns in a database with the same name but with different datatype
/// </summary>

0 comments on commit cf750c3

Please sign in to comment.