Sometimes you want to change the column names to make them more readable, SQL aliases are used to change the names of tables or columns headings, it is used as follows:
SELECT column_name AS new_name
FROM TableName ;
FROM TableName AS new_name ;
Note: The use of the AS keyword is optional but its use is recommended.
SELECT [CardType] AS [Card Type] ,[CardNumber] AS [Card Number] FROM [Sales].[CreditCard];
The columns after a concatenation or computing are not named, it is recommended to rename these columns:
- Without Alias
SELECT [Title] ,[FirstName] ,[LastName] ,[FirstName] +' '+ [LastName] FROM [Person].[Person] ;
- With Alias
Here now with the application of the alias:
SELECT [Title] ,[FirstName] ,[LastName] ,[FirstName] +' '+ [LastName] AS [Full Name] FROM [Person].[Person];
Aliases on a Table
This can help to have shorter names, simpler. This is particularly useful when you use Joins between tables and sometimes it is required in Self-Joins.