Rule Definition
Table aliasing is a common and helpful practice.
It saves you keystrokes when referencing columns anywhere in your query.
It improves the readability of your query when you are referencing many tables. Aliases let you give those tables a short name plus a little meaning to how they are being used.
It is even required when you join a table to itself or when you join to the same table multiple times.
Remediation
Check the statement and if so, add aliases to your tables.
Violation Code Sample
select date,
sales.ord_num,
qty,
salesdetail.title_id,
discount,
price,
total = qty * price * (1 - discount/100)
from sales, salesdetail, titles
where sales.stor_id = @stor_id
and sales.ord_num = salesdetail.ord_num
and titles.title_id = salesdetail.title_id
order by date desc, sales.ord_num
Fixed Code Sample
select sal.date,
sal.ord_num,
saldet.qty,
saldet.title_id,
saldet.discount,
titl.price,
total = saldet.qty * titl.price * (1 - saldet.discount/100)
from sales sal
join salesdetail saldet on sal.ord_num = saldet.ord_num
join titles titl on titl.title_id = saldet.title_id
where sal.stor_id = @stor_id
order by sal.date desc, sal.ord_num
Related Technologies
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.