Home

Tables should be aliased

Description

    When writing PL/SQL code, it is good practice to alias tables in order to make the code more readable and easier to maintain. Aliasing a table is done by assigning a shorter name to a table, which is then used in the code instead of the full table name. This makes the code more concise and easier to read, as well as easier to maintain if the table name changes in the future. Aliasing tables is also useful when joining multiple tables, as it can help to avoid confusion when referencing columns from multiple tables.

Key Benefits

  • Improved query performance: Tables aliasing can improve query performance by reducing the amount of data that needs to be scanned and processed.
  • Easier to read and understand: Aliasing tables can make queries easier to read and understand, as the same table can be referred to by different names.
  • Reduced complexity: Aliasing tables can reduce the complexity of queries by allowing the same table to be used multiple times in the same query.

 

Non-compliant Code Example

SELECT 
    NAME,
    ADDRESS,
    CREDIT_LIMIT       
FROM CUSTOMERS                  --Non compliant code (Tables are not aliased)
INNER JOIN VENDOR               --Non compliant code (Tables are not aliased)
	ON VENDOR.NAME IS NOT NULL AND VENDOR.NAME = CUSTOMERS.NAME;

Compliant Code Example

SELECT 
    cust.NAME,
    cust.ADDRESS,
    cust.CREDIT_LIMIT       
FROM CUSTOMERS cust                 --Compliant code (Aliased used for tables)
INNER JOIN VENDOR ven               --Compliant code (Aliased used for tables)
	ON ven.NAME IS NOT NULL AND ven.NAME = cust.NAME
Visual Expert 2024
 VEPLSQLRULE150