Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Using Table Aliases

Using Table Aliases

The readability of a SELECT statement can be improved by giving a table an alias, also known as a correlation name or range variable. A table alias can be assigned either with or without the AS keyword:

  • table_name AS table alias

  • table_name table_alias

In the following example, the alias c is assigned to Customer and the alias s is assigned to Store.

USE AdventureWorks;
GO
SELECT c.CustomerID, s.Name
FROM Sales.Customer AS c
JOIN Sales.Store AS s
ON c.CustomerID = s.CustomerID

If an alias is assigned to a table, all explicit references to the table in the Transact-SQL statement must use the alias, not the table name. For example, the following SELECT generates a syntax error because it uses the name of the table when an alias has been assigned:

SELECT Sales.Customer.CustomerID, /* Illegal reference to Sales.Customer. */
    s.Name
FROM Sales.Customer AS c
JOIN Sales.Store AS s
ON c.CustomerID = s.CustomerID

Community Additions

ADD
Show:
© 2015 Microsoft