T-SQL - Aliasing using "=" versus "as"

Viewed 13835

Is there any particular reason (performance or otherwise) to use AS ahead of = when aliasing a column?

My personal preference (for readability) is to use this:

select
alias1     = somecolumn
alias2     = anothercolumn
from
tables
etc...

instead of this:

select
somecolumn as alias1
anothercolumn as alias2
from
tables
etc...

Am I missing out on any reason why I shouldn't be doing this? What are other people's preferences when it comes to formatting their columns?

16 Answers

Since I write SQL for several different relational database management systems, I prefer to use a syntax which works on all of them, which normally means writing ANSI compatible SQL. My normal formatting preference is:

SELECT S.name AS SchemaName, O.name AS ObjectName, C.column_id AS ColumnId, C.name AS ColumnName FROM sys.schemas AS S INNER JOIN sys.objects AS O ON S.schema_id = O.schema_id INNER JOIN sys.columns AS C ON O.object_id = C.object_id ORDER BY S.name ASC, O.name ASC, C.column_id ASC;

As an alternative formatting of the above, the following makes it easier to see the column alias names:

SELECT S.name AS SchemaName, O.name AS ObjectName, C.column_id AS ColumnId, C.name AS ColumnName FROM sys.schemas AS S INNER JOIN sys.objects AS O ON S.schema_id = O.schema_id INNER JOIN sys.columns AS C ON O.object_id = C.object_id ORDER BY S.name ASC, O.name ASC, C.column_id ASC;

Related