更新时间:2023-02-06 07:53:44
我通常做的事情是这样的
What I typically do is something like
WHERE ( @UserID IS NULL OR UserID = @UserID )
为什么它没有被索引?索引 FK 通常是一种很好的形式,因为您经常加入它们......
And why isn't it indexed? It's generally good form to index FKs, since you often join on them...
如果您担心查询计划存储,只需执行以下操作:创建过程...重新编译
If you're worried about query plan storage, simply do: CREATE PROCEDURE ... WITH RECOMPILE