问题
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