0

If I have a T-SQL Query like the following:

SELECT [TableAlias].[ColumnOne] AS [Column 1]
FROM [dbo].[TableName] AS [TableAlias]

Will there be a performance difference if I compare the above query with this one below?

SELECT [TableAlias].[ColumnOne] [Column 1]
FROM [dbo].[TableName] [TableAlias]

Assuming the table [dbo].[TableName] has a lot of data in it.

Any help / insight will be appreciated.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Shiasu-sama
  • 1,179
  • 2
  • 12
  • 39
  • Have a look at the _actual execution plan_ to see what the difference is for executing the query. Compilation time may vary and could be improved by aliases since they only require a limited symbol table search to identify the data source and not a broader search ensure that it is unambiguous. – HABO May 21 '20 at 13:38
  • To clarify my previous comment: Using _qualified_ column names, whether with the table name or an alias, can improve the performance of the compiler. Semantic analysis for a reference to `Foo` requires searching the symbol table for _all_ applicable occurrences of `Foo`. The result must be unambiguous. A reference to `Bar.Foo`, whether `Bar` is a table name or alias within the query, requires only locating `Foo` within the `Bar` entries in the symbol table. Using qualified names is a best practice and the performance penalty, if any, is outweighed by the benefits. – HABO May 21 '20 at 20:04

2 Answers2

2

There is no difference. Unless you consider the time used by the parser to read few bytes...

user_0
  • 3,173
  • 20
  • 33
  • So if we consider the time used by the parser to read a few bytes; the performance difference would be just fractions of a second, regardless of how much data is in the table right? – Shiasu-sama May 21 '20 at 09:01
  • 1
    Yes. Fraction of millisecond. And you have best readability, as pointed from zealous. – user_0 May 21 '20 at 09:07
2

Not at all and the performance impact is negligible. Alias give you much better time readability in the query as it removed ambiguity.

zealous
  • 7,336
  • 4
  • 16
  • 36
  • I agree that using AS in aliases improves readability. Reason I'm asking is: Another developer removed the AS in aliases of my original T-SQL, making it more difficult for me to read, so I wondered if there are performance implications. – Shiasu-sama May 21 '20 at 09:04