Is it better to use column aliases with or without the AS keyword?

What's better?

Select TestColumn TC 

or

 Select TestColumn AS TC 

I prefer the former, but I'm not sure if this is the modern way to declare an alias.

+6
source share
5 answers

These two are equivalent for most purposes. I prefer the explicit notation AS.

One of the reasons why I use the AS form is because in the DBMS, which I mainly use, it provides a measure of protection against new keywords that appear when updating the system. I.e:

 SELECT TestColumn KeyWord 

where "KeyWord" becomes a keyword in a future version, it can cause problems, whereas on a specific system, using:

 SELECT TestColumn AS KeyWord 

remains in power.

I recently found out (it was said) that Oracle does not support AS in table aliases.

 FROM TableName T1 -- OK in Oracle FROM TableName AS T1 -- Not OK in Oracle 

If this is accurate (I have not tested it), then I believe that AS is a mistake.

This is your choice; these notation is equivalent.

+9
source

I prefer the second (using "AS"). If this works anyway, just use what you prefer and use it consistently.

+4
source

It should not matter what you use, just stick with it. I prefer AS personally, this is a more specific feeling.

+3
source

Both should work. Choose what you prefer or whatever you add to the readability of the request. I personally usually have an alias with "AS", only smidge is more readable in my opinion.

+3
source

It depends.

More specifically, it depends on the coding standards for the environment in which you work. Regardless of your personal preferences, you may have to adapt your style to align it with the coding standards of the group or team you're working on.

More importantly, your SQL should look just like the rest of the SQL around it, in order to facilitate testing and debugging of your code when it is passed to the testing team and, ultimately, to the operations and maintenance team in production.

+3
source

Source: https://habr.com/ru/post/906881/


All Articles