Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««23456

Time Bomb Design - A Longer Fuse Expand / Collapse
Author
Message
Posted Wednesday, June 9, 2010 8:46 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, October 10, 2014 2:06 PM
Points: 89, Visits: 482
RichB (6/9/2010)
Thomas-282729 (6/8/2010)
Again, what you are suggesting is a poorly written query where the developer uses the wrong alias (A.Id instead of B.Id). How does that improve clarity in the scenario where say "EmployeeId" exists in five or ten tables? It will be just as easy to mistakenly write A.EmployeeId instead of B.EmployeeId as it would writing A.Id vs B.Id.



Well, in this case the difference between getting a.EmployeeId instead of b.EmployeeId is likely to be less significant than getting

a.ID when you wanted b.ID where a.ID comes from Employee a ([employee]Id, name, stuff) and b.ID comes from ProjectStaff([project]Id, employeeid, stuff)

Also - that bug is almost impossible to find, whereas with properly named columns its pretty straightforward.


How do you figure it is easier to find? Suppose the PK is named EmployeeId. It is just as easy to write A.EmployeeId instead of B.EmployeeId in the join as it would to write A.Id vs B.Id. In fact, I would say that having the PK be named "Id" makes it easier to see which column is the PK and which column is the FK. That would make it easier to find situations where the developer accidentally joined the column to itself (e.g. A.EmployeeId = A.EmployeeId).

Of course, the developer used a better alias, then it would be even easier to see a problem.
Post #935103
Posted Thursday, June 10, 2010 9:17 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 12:14 PM
Points: 1,706, Visits: 4,848
Thomas-282729 (6/9/2010)
RichB (6/9/2010)
Thomas-282729 (6/8/2010)
Again, what you are suggesting is a poorly written query where the developer uses the wrong alias (A.Id instead of B.Id). How does that improve clarity in the scenario where say "EmployeeId" exists in five or ten tables? It will be just as easy to mistakenly write A.EmployeeId instead of B.EmployeeId as it would writing A.Id vs B.Id.



Well, in this case the difference between getting a.EmployeeId instead of b.EmployeeId is likely to be less significant than getting

a.ID when you wanted b.ID where a.ID comes from Employee a ([employee]Id, name, stuff) and b.ID comes from ProjectStaff([project]Id, employeeid, stuff)

Also - that bug is almost impossible to find, whereas with properly named columns its pretty straightforward.


How do you figure it is easier to find? Suppose the PK is named EmployeeId. It is just as easy to write A.EmployeeId instead of B.EmployeeId in the join as it would to write A.Id vs B.Id. In fact, I would say that having the PK be named "Id" makes it easier to see which column is the PK and which column is the FK. That would make it easier to find situations where the developer accidentally joined the column to itself (e.g. A.EmployeeId = A.EmployeeId).

Of course, the developer used a better alias, then it would be even easier to see a problem.

Fortunately, in almost every company I've worked for, there are designated database developers who write the stored procedures and views. On the application and reporting side, no one is writing SQL queries, and in fact they don't even have access to the tables, only exec permission on the procedures. Therefore, arguments about what column names would save the most keystrokes to enter or what column names would be the most understandable to a casual user are not taken into consideration when designing the data model. There are cases where application developers will request that result columns from a stored procedure be aliased in a certain way to make them more understandable to them personally, and I don't have so much of a problem with that, so long as the underlying tables themselves are properly normalized and conform to a standard naming convention.
Post #935430
Posted Thursday, June 10, 2010 2:36 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 7:36 AM
Points: 2,907, Visits: 1,832
There seems to be an assumption that there is a single field acting as the PK. This isn't necessarily true.

As to calling things ID because its easier for developers to write boiler plate code, that sounds like a violation of software engineering principles. We want to aim for loose coupling and strong cohesion.


LinkedIn Profile
Newbie on www.simple-talk.com
Post #935715
Posted Thursday, June 10, 2010 10:14 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, October 10, 2014 2:06 PM
Points: 89, Visits: 482
David.Poole (6/10/2010)
There seems to be an assumption that there is a single field acting as the PK. This isn't necessarily true.

As to calling things ID because its easier for developers to write boiler plate code, that sounds like a violation of software engineering principles. We want to aim for loose coupling and strong cohesion.


Calling things TableNameID in one special set of circumstances because developers utilize bad development practices also sounds like a violation of software engineering principles. If it makes it easier to write boiler plate code, that is a side effect as opposed to driving reason for the naming scheme.
Post #935824
Posted Monday, June 14, 2010 10:07 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 8:38 AM
Points: 1,070, Visits: 908
Might sound like it, but only to someone who doesn't understand the language...


Post #936983
« Prev Topic | Next Topic »

Add to briefcase «««23456

Permissions Expand / Collapse