且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

sqlserver缓存程序-只能使用一次清除缓存计划

更新时间:2022-06-02 06:16:46

plan cache非常大。将仅仅使用一次的缓存计划清除,而不用清除整个cache.

declare @sid varbinary(64)
declare cur01 cursor for
select  plan_handle from 
(
SELECT  plan_handle  
FROM sys.dm_exec_cached_plans AS cp 
CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) st
WHERE cp.cacheobjtype = N'Compiled Plan'
AND cp.objtype IN (N'Adhoc', N'Prepared')
AND cp.usecounts =1 
and  text   like 'select%'
) c
open cur01
fetch next from cur01 into @sid
while @@fetch_status=0
begin
DBCC FREEPROCCACHE(@sid)
fetch next from cur01 into @sid
end
close cur01
deallocate cur01
go



版权声明:本文博客原创文章。博客,未经同意,不得转载。




本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4713077.html,如需转载请自行联系原作者