• Nils Gustav Stråbø (9/22/2012)


    5.Avoid the use of negative logic wherever possible (NOT EXISTS, NOT IN ...)

    Why? What would you use instead when you need this form negative logic? When an inexperienced SQL developer sees this line he/she could end up using a LEFT JOIN negative_table with WHERE negative_table .column IS NULL combined with a GROUP BY or DISTINCT which will break one of your other best practices and would usually perform worse.

    I would rather explain the difference between NOT EXISTS and NOT IN when the column in NOT IN is nullable.

    Thanks for the articles. I hadn't even thought of that one, but I will add an item for this. The reason this item was here originally was because unless I'm mistaken, negative logic forces a table scan. Am I wrong on that one?