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

前端 未结 5 1730
有刺的猬
有刺的猬 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:13

    Not sure about SQL Server but in other databases the standard method is:

    SELECT COUNT(*) FROM BigTable where SomeCol = 200;
    

    Actual efficiency depends on your indexes etc.

提交回复
热议问题