Do you use this
IF (SELECT COUNT(*) FROM SomeTable
WHERE SomeColumn = SomeValue ) > 0
Or do you use this
IF EXISTS (SELECT * FROM SomeTable WHERE SomeColumn = SomeValue )
If you answered COUNT(*) then maybe you should take a look these two articles
Andrew Kelly has a nice post on SQLBlog
http://sqlblog.com/blogs/andrew_kelly/archive/2007/12/15/exists-vs-count-the-battle-never-ends.aspx
Matija Lah has a good post on his snaps & snippets blog
http://milambda.blogspot.com/2006/10/exists-or-not-exists-that-is-question.html
Sunday, December 16, 2007
EXISTS or COUNT(*) Which Do You Use To Check How Many Rows There Are?
Posted by Denis at 11:50 AM
Labels: Performance, Performance Tuning, SQL Server 2000, SQL Server 2005, SQL Server 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment