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

前端 未结 5 1720
有刺的猬
有刺的猬 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 19:06

    This is what you want instead of the IF statement

      SELECT ISNULL(
         (SELECT TOP 1 1 FROM BigTable where SomeCol = 200), 0);
    

提交回复
热议问题