Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Using Table Aliases

SQL Server 2000

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 this example, the alias p is assigned to publishers.

USE pubs
SELECT p.pub_id, p.pub_name
FROM publishers AS p

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 Customers.CustomerID, /* Illegal reference to Customers. */
       Cst.FirstName, Cst.LastName
FROM Northwind.dbo.Customers AS Cst

See Also

FROM

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.