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)

  • Probably a fairly minor point but even a very very small difference can be worth it when you have a piece of code being run thousands of times a second.

    Also another good place to use a 1 instead of a * is when doing a count.

    For example

    SELECT COUNT(1) FROM sysobjects

    vs

    SELECT COUNT(*) FROM sysobjects

    Again a fairly minor difference but one that can have a large impact if the code is run often enough.

    Kenneth

    Kenneth FisherI was once offered a wizards hat but it got in the way of my dunce cap.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/[/url]Link to my Blog Post --> www.SQLStudies.com[/url]