What are the benefits of using A B C as table alias in a SQL query just based on the order the tables are added in the FROM clause?

Viewed 958

We sent some of our new starters off for some basic SQL training and they came back renaming tables as A for the first table and B for the second and so on. One of them said they were told: - It was quicker to type - If you use the starting letter then you run into issues when you have tables starting with the same name

In my opinion this seriously sacrifices the readability of the query and I'm probably going to be the one reviewing the code they write. I just want to make sure I'm not missing something before I tell them to either use the first letter and number if there are multiple tables or just an abbreviated version of the table name. In most cases the table names are only 5-8 letters long so I'd prefer they use the full name than an alias that doesn't describe the table in any way.

Are there any other benefits?

1 Answers

well, I would like to point two facts with examples

1.- select * from pupils pup inner join pupils pup2 on pup.id=pup2.otherId. In this example, I know exactly what I am linking because I am using the same table twice, really useful for queries where the same table is linked twice at least.

2.- readability is not a problem if you chose well the alias:

 select * from pupils pup inner join parents  payees on 
  parents.id=pupils.parentid
  inner join parents tutors on pupils.tutorid=tutors.id

In this case, readability is not an issue and I still know and distinguish which are the parents who pay and the tutors or legal guardians.

Related