2010年3月5日 星期五

Top 8 SQL Best Practices

Top 8 SQL Best Practices

1) Always use explicit joins. If I mean INNER JOIN, then I use INNER JOIN. No use of just plain "JOIN". Never, ever, ever use a comma join -- I consider that a mistake. If I explicitly state "CROSS JOIN" then I know I have consciously made that decision. Also, keep join conditions in an ON or USING clause; they should not go in the WHERE clause. I also put my join conditions in parentheses; for whatever reason, I find:
ON (foo=bar AND baz=bop) WHERE a=b
is easier to see that the join condition contains 2 conditions than
ON foo=bar AND baz=bop WHERE a=b

沒有留言: