Qyouu
使查询不可搜索的最常见的事情是在where子句中的函数内包含一个字段:SELECT ... FROM ...WHERE Year(myDate) = 2008SQL优化器无法在myDate上使用索引,即使存在索引也是如此。它实际上必须为表的每一行评估此函数。使用起来好多了:WHERE myDate >= '01-01-2008' AND myDate < '01-01-2009'其他一些例子:Bad: Select ... WHERE isNull(FullName,'Ed Jones') = 'Ed Jones'Fixed: Select ... WHERE ((FullName = 'Ed Jones') OR (FullName IS NULL))Bad: Select ... WHERE SUBSTRING(DealerName,4) = 'Ford'Fixed: Select ... WHERE DealerName Like 'Ford%'Bad: Select ... WHERE DateDiff(mm,OrderDate,GetDate()) >= 30Fixed: Select ... WHERE OrderDate < DateAdd(mm,-30,GetDate())