Reference: https://www.cnblogs.com/wy123/p/7190785.html Reference: https://www.cnblogs.com/Irving/p/3951220.html
if object_id('tempdb: #t_remove_expired_plan') is not NULL Drop Table#t_remove_expired_planGOCreate Table#t_remove_expired_plan (IDint Identity(1,1), Plan_handlevarbinary( -))GOInsert into#t_remove_expired_plan (plan_handle)SelectQs.plan_handle fromsys.dm_exec_query_stats QSwhereCreation_time< DateAdd(HH,- -,getdate())GODeclare @exists_data bit = 1Declare @v_plan_handle varbinary( -)Declare @str_sql varchar( +) while @exists_data = 1begin Select Top 1 @v_plan_handle =Plan_handle from#t_remove_expired_planif(@v_plan_handle is not NULL) begin Executesp_executesql N'DBCC Freeproccache (@plan_handle)'N'@plan_handle varbinary ($)',@plan_handle = @v_plan_handle End Delete Top(1) from#t_remove_expired_planif exists(Select 1 from#t_remove_expired_plan)begin Set @exists_data = 1 End Else begin Set @exists_data = 0 EndEnd
Reference: https://www.cnblogs.com/quanweiru/p/5577421.html
Go [Dapper] Parameterized query slow