• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HF SQL and Normalizing

 
Ken Duncan
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My team is having issues these days because one of them has been converted to Hibernate, including the view that primary keys can be arbitrary integers. That seems to violate all rules of normalization. Does your book comment on the issue of what makes a proper primary key?

Ken
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having no meaning in a primary key is usually a good thing.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm no DB guru, but those who are have repeatedly told me that primary keys should have no semantic meaning. It's just an opaque identifier that carries no data of its own.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34205
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ken,
This is a point of high contention. It is certainly safer to have a primary key as an arbitrary number. Some people use business values. With that approach, there is the risk that something may change. For example, a person's social security number seems unique. But what happens if there was a typo or mistake?
 
Ken Duncan
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Ken,
This is a point of high contention. It is certainly safer to have a primary key as an arbitrary number. Some people use business values. With that approach, there is the risk that something may change. For example, a person's social security number seems unique. But what happens if there was a typo or mistake?


It might be safer to use an arbitrary number but it makes programming much harder because you can't use your key as a meaningful search term any longer. In fact, I was really surprised to see anyone even suggest such a thing as an arbitrary key, as though all the research done in the 1980's and 1990's on relational database by people like Chris Date was not only not correct but not even engaged. It seems to me that before one maintains that arbitrary keys are best one would be well-advised to tell me why all the work that has gone on before doesn't matter.

Ken
 
Lynn Beighley
author
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a topic people feel very strongly about, and I'm not going to take sides on this one. I try to be agnostic about this in the book, but in practice I will confess that I tend to use artificial keys. I tend to agree with Jeanne (and even use a similar example in the book). When you're in the middle of trying to figure out why you even need a key at all, going into the great debate is a little off track.
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
I'm no DB guru, but those who are have repeatedly told me that primary keys should have no semantic meaning. It's just an opaque identifier that carries no data of its own.


From a data modeling standpoint, using a surrogate key instead of a natural key removes the business requirements from your database key structure. If requirements change for the data related to the business, you do not have to change the key structure of your database. This decoupling can sometimes be a disadvantage from a user standpoint with ad-hoc queries.

The advantage of a natural key is that it allows the user with business knowledge to query the data without understanding surrogate key relationships.

From a SQL standpoint, it really makes little difference with respect to your query beyond performance of number keys joining to number keys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic