“SELECT TOP 1 1” VS “IF EXISTS(SELECT 1”

前端 未结 5 1727
有刺的猬
有刺的猬 2020-12-29 18:29

I have some .NET code that checks for the existence of a SQL record at a moderately-high interval. I am looking to make this check as \"cheap\" as possible.

I\'m wo

5条回答
  •  臣服心动
    2020-12-29 19:14

    I would definitely go for the 2nd option:

    SELECT TOP 1 1
    FROM   BigTable
    WHERE  SomeColumn = 200 
    

    The execution plan is simpler and efficient even when I/O and CPU numbers are mostly the same.

提交回复
热议问题