Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Time Bomb Design - A Longer Fuse


Time Bomb Design - A Longer Fuse

Author
Message
Thomas-282729
Thomas-282729
SSC Journeyman
SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)

Group: General Forum Members
Points: 97 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.
Eric M Russell
Eric M Russell
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4612 Visits: 9545
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.


"The universe is complicated and for the most part beyond your control, but your life is only as complicated as you choose it to be."
David.Poole
David.Poole
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3678 Visits: 3115
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
Thomas-282729
Thomas-282729
SSC Journeyman
SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)SSC Journeyman (97 reputation)

Group: General Forum Members
Points: 97 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.
RichB
RichB
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1102 Visits: 1015
Might sound like it, but only to someone who doesn't understand the language...



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search