Inconsistently Advised to Use Alias For CTE (ST010)
Simple statements do not flag this:
WITH CTE1 AS (SELECT TestColumn FROM dbo.TestTable)
SELECT a.TestColumn FROM CTE1 a
INNER JOIN CTE1 b ON a.TestColumn = b.TestColumn;
However, more complex statements do:
WITH CTE1 AS (SELECT TestColumn FROM dbo.TestTable),
CTE2 AS (SELECT TestColumn FROM CTE1),
CTE3 AS (SELECT TestColumn FROM CTE2)
SELECT CTE3.TestColumn FROM CTE3
INNER JOIN CTE2 ON CTE3.TestColumn = CTE2.TestColumn;
In the final select clause, both CTE2 and CTE3 are flagged with 'Use alias for all table sources' (ST010).
Seems a bit OTT to suggest references to CTEs are aliased? I accept that a CTE defines, in relational terms, a 'table'. However, to me, this smells like obfuscation. Happily use aliases for table/view names though not SQL Prompt's auto alias facility. Both my table aliases and CTE names are typically very short.
If flagging 'Use alias for all table sources' for CTEs is appropriate consider:
1. Separate flagging of CTEs and tables/views into different conditions.
2. Be consistent about CTE aliasing?