Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Joins: Table aliases are NOT required! Expand / Collapse
Posted Friday, August 14, 2009 10:05 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, November 19, 2015 2:43 PM
Points: 67, Visits: 231
Why does everyone think that table aliases are a necessary part of the syntax? They are not.

SELECT Emp.Empid, Emp.EmpFirstName, Emp.EmpLastName, Dept.DepartmentName
FROM Employee Emp
INNER JOIN Department dept
ON Emp.Departmentid=Dept.Departmenttid

It's easier to read this as:

SELECT Employee.Empid, Employee.EmpFirstName, Employee.EmpLastName, Department.DepartmentName
FROM Employee
INNER JOIN Department
ON Employee.Departmentid=Department.Departmenttid

Some people will complain about "all the typing". However, I don't believe for one second that the speed of writing SQL code is constrained by HOW FAST you can type. It's how fast you can design and think that is the limiting factor! Besides, copy and paste are your friends.

The next thing you know, you'll be using one-letter table aliases, even in complex queries, and then the code is VERY hard to read later on. Table aliases are SOMETIMES required, but not in simple joins like this. PLEASE don't teach people in "SQL 101" to use table aliases in simple joins. Code readability is far too important. Please!

David Walker
Post #771086
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse