T-SQL Tutorials - TSQLTutorials.com | ||
Aliases - naming and renaming | ||
|
|
IntroductionAliases are used in TSQL to rename things. There are two main types of aliases. Aliases can be used to rename columns within a query, or name columns. Aliases can also be used to name datasets, or rename tables within a query. The keyword AS can be used for created aliases, however it is optional. Column Aliases
Often in a result set you may want to rename a column, so that it makes more sense in a particular context. For example you may want to refer to the column 'EMPID' as 'Employee_ID'. The following two examples will rename the column within the dataset, both are the same, with the first using the optional AS keyword. Table Aliases
Table Aliases are very helpful in cases when you have to rename a table, or want to rename a table, in a query for convenience sake. First of all some table names can be very long and inconvenient to type out. An example of a long table name could be: '2006_NorthAmerican_Sales'. Now this table name isn't to long if you have to type it out once, but if you have to reference it many times in a query, it could become tedious. This example will show how to create a table alias and use it:
Using AS keyword
SELECT |
|