5/14/2013

Top 10 Bad Practices When Writing #SQL

What are some bad practices I see when viewing SQL code.
  1. Spaces in the table names
    1. ...From [User Info]
  2. Spaces in field names
    1. Select a.[First Name]...
  3. Dates stored as Strings
    1. CommissionDate as String
  4. Lack of descriptive 'Alias' names
    1. Inner Join Contacts a with (nolock)
  5. Inconsistent programming styles
    1. Using CTE, then Temp Tables, then Table Variables
  6. Unnecessary code 
    1. i.e. "Ltrim(RTrim(CustomerName))"
  7. Scattering Tables across Multiple Databases on a Server
    1. ...From Sales.dbo.Customer Inner Join Leads.dbo.Customer...Inner Join Demographics.dbo.State
  8. Messy Code
    1. Difficult to follow, not spaced for easy reading
  9. Using Cursors
    1. Use Looping or Joins more efficiently
  10. No Comments / Documentation
    1. Please add comments to inform next person what you are doing

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Thoughts to Ponder