August 7th, 2008

AS (Column Aliases)

Posted by admin in C. SELECT Statement

A column’s default display name is its column name in the table definition.
You can use the AS clause to create a column alias name.
A column alias is an alternate name that you have picked for the displayed result.
An alias name can be used to give a name to a derived column, such as an expression or a column function.
An alias name does not change the name of a column in a table.

SELECT column1 AS alias1,
       column2 AS alias2, ...
  FROM table1, table2, ...;

> A column alias immediately follows the column name in the SELECT clause.
> A column alias does not change the column name in the table definition.
It only changes the result table and exists only for the duration of the statement.
> Oracle and DB2 display unquoted column names and aliases in uppercase.
> When the default name is displayed, underscores are replaced with spaces in some RDBMS systems such as DB2.
> If the alias is a single word with only letters, digits, and underscores, and it is not a reserved word, you do not need quotes.
> If the alias name contains spaces, special characters, or punctuation, enclose the alias in single or double quotes.
> You should make a habit of using quotes around alias names, just for consistency and partability to other RDBMS systems.
> With Access and PostgreSQL, AS is required. With others, is is optional.
But it should always be included when adding an alias name for portability.
> Oracle’s SQL*Plus command line processor truncates column aliases to the number of characters in the table’s column definition. DECIMAL(3) ‘PERCENT’ becomes ‘PER’.

Comments are closed.

Sorry, the comment form is closed at this time.