Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-2454

Columns should be aliased

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Add an alias to "xxx"
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Legacy Key:
      ColumnsShouldBeAliasedCheck
    • Covered Languages:
      PL/SQL
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      30min

      Description

      Consistently using aliases for column names is useful for several reasons. The main one is that the code is independant from potential database modifications - when a column has been renamed to comply with standards for instance. Another reason is to remove ambiguity when querying several tables that may have equivalent column names.

      Noncompliant Code Example

      BEGIN
        SELECT
          emp.name, -- Noncompliant - should be aliased
          dpt.name -- Noncompliant - should be aliased
        INTO employeesArray
        FROM employee emp INNER JOIN department dpt
        ON emp.DepartmentID = dpt.ID;
      END;
      /
      

      Compliant Solution

      BEGIN
        SELECT
          emp.name employee_name, -- Compliant
          dpt.name departement_name -- Compliant
        INTO employeesArray
        FROM employee emp INNER JOIN department dpt
        ON emp.DepartmentID = dpt.ID;
      END;
      /
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: