Normally one would think that adding a new, unused column to an existing database table wouldn't break anything, right?
Well, normally it wouldn't, unless the column name is the same as on another table, and if some of your queries don't use the table.column syntax when referring to columns.
For example, assume you have two tables with a many-to-one relationship:
EmployeeEmployeeIDEmployeeNameDepartmentIDActive
DepartmentDepartmentIDDepartmentName
Notice that the Employee table has an "Active" column, but the Department table does not.
Down the road, you decide to add an "Active" column to the Department table, too. You figure since it's a brand-new column, it shouldn't break anything. However, if your application uses queries like this:
SELECT EmployeeName, DepartmentName, Active FROM Employee e INNER JOIN Department d ON e.DepartmentID = d.DepartmentID WHERE Active=1
they'll break with an "ambiguous column name 'Active'" error as soon as you add an "Active" column to the Department table, because now the "Active" column in the above query is ambiguous: does it refer to Employee.Active or Department.Active?
The solution to all this is establishing some good naming & query-writing habits:
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Ben Strackany
E-mail