I want to know if "Paris" exists in a table of cities. I've read that
is better than
because in the first case, as soon as it hits the record containing 'Paris' it stops running the query and displays the result while in the second it will read every record in the table before displaying the result.
However, when I click on "Include actual execution plan" before running these two SELECT statements, I get what seems to be the exact same result either way. In particular, the "Clustered Index Scan icon, which shows 98% indicates that the same number of rows have been read in both cases.
Is one really better than the other?
Code:
IF EXISTS(SELECT * FROM tblCities WHERE fldCityName = 'Paris') PRINT 'Paris Exists'
Code:
IF(SELECT COUNT(*) FROM tblCities WHERE fldCityName = 'Paris') > 0 PRINT 'Paris Exists
However, when I click on "Include actual execution plan" before running these two SELECT statements, I get what seems to be the exact same result either way. In particular, the "Clustered Index Scan icon, which shows 98% indicates that the same number of rows have been read in both cases.
Is one really better than the other?