SQL Server Performance

Sequence to be followed while writing stored procedure

Discussion in 'SQL Server 2005 T-SQL Performance Tuning' started by sqlserverperformanceforbk, Feb 24, 2009.

  1. I am going to write the stored procedure with lot of tables and joins. I read somewhere that we need to follow the sequence while doing joins but now I am unable to find that article [:(]. Could any one help to follow the sequene while writing the stored procs(like which table should come first while selecting etc..). Please help me on this.
  2. Could anyone help me on this please?
  3. Adriaan New Member

    I usually start with the table that contains the "core" data, then add the related tables "from left to right" - expanding the information in a linear fashion.
    Tables with criteria always come at the start of the joins.
    I try to avoid RIGHT JOINs as they go against that flow - you can usually rewrite as a RIGHTy as a LEFTy.
    Other than that, you can usually depend on SQL Server to work out the best execution plan - you should be aware that SQL does not always work according to your plan, although this will have no effect on which results will be returned.
  4. FrankKalis Moderator

    As long as the resultset is correct, it is really a matter of personal taste and coding style. The optimizer will mostly rearrange the statement anyway behind the scenes whenever it deems to be appropriate.

Share This Page