G-3120: Always use table aliases when your SQL statement involves more than one source.
Major
Maintainability
Reason
It is more human readable to use aliases instead of writing columns with no table information.
Especially when using subqueries the omission of table aliases may end in unexpected behaviors and results.
Also, note that even if you have a single table statement, it will almost always at some point in the future end up getting joined to another table, so you get bonus points if you use table aliases all the time.
Example (bad)
1 2 3 4 5 6 |
|
Example (better)
1 2 3 4 5 6 |
|
Example (good)
Using meaningful aliases improves the readability of your code.
1 2 3 4 5 6 |
|
Example Subquery (bad)
If the job
table has no employee_id
column and employee
has one this query will not raise an error but return all rows of the employee
table as a subquery is allowed to access columns of all its parent tables - this construct is known as correlated subquery.
1 2 3 4 5 6 |
|
Example Subquery (good)
If the job
table has no employee_id
column this query will return an error due to the directive (given by adding the table alias to the column) to read the employee_id
column from the job
table.
1 2 3 4 5 6 |
|