Improvement in Select with Sql Server

  • Which of the commands below has better performance in Sql Server 2000

    1) If Not Exists(Select Cliente.CD_Cliente From Cliente Where Cliente.CD_Cliente = @CD_Cliente)

    or

    2) If (Select count (*) From Cliente Where Cliente.CD_Cliente = @CD_Cliente) = 0)

    I am using this commands inside of Store Procedure, or other form would exist of executing this better command.

    Thankful at once.

    Claudinei

    Brazul Transport of Vehicles Ltd.

    Visual Basic

    Sql Server

    ASP


    Visual Basic
    Sql Server
    ASP

  • I would say, that EXISTS almost always performs better, because it can stop once the logical test is true, while COUNT walks through the whole resultset, even after the condition is met.

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply