Home Forums SQL Server 2005 T-SQL (SS2K5) EXISTS Subqueries: SELECT 1 vs. SELECT * (Database Weekly 11.02.2008) RE: EXISTS Subqueries: SELECT 1 vs. SELECT * (Database Weekly 11.02.2008)

  • On the specific point of "if exists", the reason to use "*" in that case is so SQL server can pick which index it wants to use, instead of putting in a specific column name and thus possibly forcing it to use a specific index. It's a minor speed advantage.

    Using "select 1" means SQL Server can use whatever index it wants, and doesn't have to look up column names. Again, a very minor improvement, but every bit counts in some busy servers.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon