我有與下面的T-SQL代碼中的一個SQL Server存儲過程中包含的:WHERE子句是困擾我如何確定存儲過程是否每次重新編譯?
insert into #results ([ID], [Action], [Success], [StartTime], [EndTime], [Process])
select
'ID' = aa.[ActionID],
'Action' = cast(aa.[Action] as int),
'Success' = aa.[Success],
'StartTime' = aa.[StartTime],
'EndTime' = aa.[EndTime],
'Process' = cast(aa.[Process] as int)
from
[ApplicationActions] aa with(nolock)
where
0 = case
when (@loggingLevel = 0) then 0
when (@loggingLevel = 1 and aa.[LoggingLevel] = 1) then 0
end
and
1 = case
when (@applicationID is null) then 1
when (@applicationID is not null and aa.[ApplicationID] = @applicationID) then 1
end
and
2 = case
when (@startDate is null) then 2
when (@startDate is not null and aa.[StartTime] >= @startDate) then 2
end
and
3 = case
when (@endDate is null) then 3
when (@endDate is not null and aa.[StartTime] <= @endDate) then 3
end
and
4 = case
when (@success is null) then 4
when (@success is not null and aa.[Success] = @success) then 4
end
and
5 = case
when (@process is null) then 5
when (@process is not null and aa.[Process] = @process) then 5
end
這是「動態的」。用戶不必將每個參數傳遞給此存儲過程。只是他們感興趣的那些用作輸出的過濾器。
我將如何去使用SQL Server Studio或Profiler來測試此存儲過程是否每次重新編譯?