Fastest way to determine if record exists

前端 未结 11 1185
清歌不尽
清歌不尽 2020-11-29 16:16

As the title suggests... I\'m trying to figure out the fastest way with the least overhead to determine if a record exists in a table or not.

Sample query:

11条回答
  •  青春惊慌失措
    2020-11-29 16:42

    SELECT CASE WHEN EXISTS (SELECT TOP 1 *
                             FROM dbo.[YourTable] 
                             WHERE [YourColumn] = [YourValue]) 
                THEN CAST (1 AS BIT) 
                ELSE CAST (0 AS BIT) END
    

    This approach returns a boolean for you.

提交回复
热议问题