The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Email Subscription

    Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 716 other subscribers

On “Bad Habits to Kick : Using AS instead of = for column aliases” (via: Aaron Bertrand)

Posted by jpluimers on 2014/01/22

A while ago, I came across an interesting post Bad Habits to Kick : Using AS instead of = for column aliases by Aaron Bertrand, a major contributor on SQLblog.com – The SQL Server blog spot on the web.

The last link indicates my problem with this “AS” versus “=”: it is SQL Server specific.

So, if you mainly use SQL Server, then it is OK (or even preferable) to use “=” for aliasing columns in human written SQL as it makes spotting the names used much easier.

= alias

[sourcecode language=”sql”]
select
tableName = o.name,
columnName = c.name,
columnTypeName = t.name
from sysobjects as o
inner join syscolumns as c on c.id = o.id
inner join systypes as t on t.usertype = c.usertype
where o.type = ‘S’
[/sourcecode]

as alias

[sourcecode language=”sql”]
select
o.name as tableName,
c.name as columnName,
t.name as columnTypeName
from sysobjects as o
inner join syscolumns as c on c.id = o.id
inner join systypes as t on t.usertype = c.usertype
where o.type = ‘S’
[/sourcecode]

But if you regularly use othter DBMS, then you should use the classic AS alias.

DBSMS that only support AS alias

At least these do not support the = way of specifying an alias:

–jeroen

via: Aaron Bertrand : Bad Habits to Kick : Using AS instead of = for column aliases.

Leave a Comment

 

Discover more from The Wiert Corner - irregular stream of stuff

Subscribe now to keep reading and get access to the full archive.

Continue reading