• eddy-644184 (2/20/2010)


    I will on the other hand always make sure that for the IF EXISTS i always select 1 field only and mostly this would be the primary key (indexed)

    EXISTS doesn't care about the columns. The column references in the SELECT inside an EXISTS are ignored by SQL, it knows that all you want is to tell if the row exists or not, and column values aren't important there.

    EXISTS (SELECT * FROM Table2 ...)

    EXISTS (SELECT pk_field FROM Table2 ...)

    EXISTS (SELECT 1 FROM Table2 ...)

    are all treated identically.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass