IF EXISTS (SELECT 1…) vs IF EXITS (SELECT TOP 1 1…)

帅比萌擦擦* 提交于 2020-05-13 11:39:27

问题


This is a purely academic question. Are these 2 statements effectively identical?

IF EXISTS (SELECT TOP 1 1 FROM Table1)
 SELECT 1
ELSE
 SELECT 0

Versus

IF EXISTS (SELECT 1 FROM Table1)
 SELECT 1
ELSE
 SELECT 0

回答1:


If you view the execution plan for these queries you can see that they are identical. Good coding practices would ask that you leave out the "TOP 1" but they should run identical either way.



来源:https://stackoverflow.com/questions/51049683/if-exists-select-1-vs-if-exits-select-top-1-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!