Have you ever wondered how I can make my SQL queries look more readable, manageable and simpler?
Well the answer is to use the ‘AS’ command as this can alias tables.
For example the below query can seem quite daunting with long table names.
USE AdventureWorks
GO
SELECT HumanResources.Department.DepartmentID, HumanResources.Department.Name, HumanResources.Department.GroupName, HumanResources.Department.ModifiedDate
FROM HumanResources.Department
However, the below query using the ‘AS’ command to alias the HumanResources.Department makes it look better, simpler and is quicker to read.
USE AdventureWorks
GO
SELECT HRDept.DepartmentID, HRDept.Name, HRDept.GroupName, HRDept.ModifiedDate
FROM HumanResources.Department AS HRDept
As you become more proficent in SQL you will find yourself aliasing tables all the time and probably won’t even notice yourself doing it
Originally published at https://parvtheitgeek.com on January 21, 2014.