Table Aliases are Wonderful. Use them on all columns!

Notice the lack of table aliases for the select list:

Select  FirstName,
            LastName,
            c.ID,
            Address1,
            Address2,
            State,
            Zip,
            Phone1,
            Phone2,
            Email,
            RegionName,
            EmployeeName
FROM Customers c
JOIN Location l
          ON c.ID = o.ID
JOIN Contact c
          ONc.ID = o.id
WHERE c.ID = @ID

Don’t do this!

If this was a database you just inherited from the last guy (or gal), it might not be obvious which column goes to which table.  So you have to take the time to figure that out before you can make the necessary changes.  And that is just wasted time. 

If you are writing a multi-table query, please use table aliases on every column in the select.  The next person to work on the code will thank you.

There are no comments yet. Be the first and leave a response!

Leave a Reply


Wanting to leave an <em>phasis on your comment?

Trackback URL http://www.dianemcnurlan.com/2008/11/table-aliases-are-wonderful-use-them-on-all-columns/trackback/