Situatie
Pentru situatiile cand avem nevoie sa aflam cand a fost rulata ultima data o anumita procedura pe baza de date am conceput o procedura ce returneaza cea mai recenta data si ora cand procedura cautata a fost rulata pe baza.
Solutie
create procedure BD_LastProcExec_prc
@NumeProc varchar(max) = null
as
IF @NumeProc IS null
SELECT object_name(m.object_id), MAX(qs.last_execution_time)
FROM sys.sql_modules m
LEFT JOIN (sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text (qs.sql_handle) st)
ON m.object_id = st.objectid
AND st.dbid = db_id()
WHERE qs.last_execution_time IS NOT NULL
GROUP BY object_name(m.object_id)
ORDER BY 1
ELSE
SELECT object_name(m.object_id), MAX(qs.last_execution_time)
FROM sys.sql_modules m
LEFT JOIN (sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text (qs.sql_handle) st)
ON m.object_id = st.objectid
AND st.dbid = db_id()
WHERE object_name(m.object_id) = @NumeProc
GROUP BY object_name(m.object_id)
Leave A Comment?