One of the guys I work with has the following to say about using SQL aliases, and he just posted the following on reddit. What do you guys think, to alias or not to alias?
....
So I've always been the odd man out of my with my dev team about how SQL should be written. I learned in school to use aliases, but I hate them personally. I find it can make the statement unreadable if long. I want to know what tables are joining to what other tables. I don't want to have to search through a 5-10 table join to figure out what "p" means, is that the products table, people, etc...?
Personally I don't find it hard to use a little double click, ctrl+c, ctrl+v. Use the full table name (of course sometimes you have to join to the same table twice which you'll be forced to use aliases in some more bizarre queries.) Ex. My style
SELECT *
FROM
People
JOIN
Orders ON People.PersonID = Orders.PersonID
JOIN
OrderDetails ON Orders.OrderID = OrderDetails.OrderID
JOIN
Products ON Products.ProductID = OrderDetails.ProductID
JOIN
Country ON People.CountryID = Country.CountryID
VS
SELECT *
FROM
People p
JOIN
Orders o ON p.PersonID = o.PersonID
JOIN
OrderDetails od ON o.OrderID = od.OrderID
JOIN
Products pr ON pr.ProductID = od.ProductID
JOIN
Country c ON p.CountryID = c.CountryID
Personal preferences yourself? I mean just consider if this query was a larger join and you had a large select statement.
I assume most people use alias as a time saver, do you think it's also more readable? Can you go to your old sql and instantly understand how your joins work?
UPDATE: Specifically I'm trying to argue that shorting the names down to single letters can make the sql statement unreadable. Changing a table from ShoeStackerCrazyProducts down to ShowProducts I think can make sense. Shorting it to sscp on the other hand would make it unreadable. Thoughts?