• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HF SQL and Normalizing

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having no meaning in a primary key is usually a good thing.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic