Assigning an Alias to Columns and Tables

Thursday, November 17, 2011

tags SQL

SQL allows you to assign an alias name to a column or a table.

Syntax


SELECT column_name AS alias_name
FROM table_name
SELECT column_name(s)
FROM table_name
AS alias_name


Examples


Assign the alias of "Customer Name" to the column "custName.


SELECT custName AS [Customer Name] 
FROM Customers


Assign the alias of "C" to the table called "tbl_Customers". This allows you to reference the table as "C" instead of the longer, original name.


SELECT * 
FROM tbl_Customers AS C

Did you find the page informational and useful? Share it using one of your favorite social sites.

Recommended Books & Training Resources

SQL Cookbook Head First SQL: Your Brain on SQL A Learners Guide