File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes HF SQL and Normalizing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "HF SQL and Normalizing" Watch "HF SQL and Normalizing" New topic
Author

HF SQL and Normalizing

Ken Duncan
Ranch Hand

Joined: Apr 30, 2007
Posts: 39
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

Joined: Jun 26, 2002
Posts: 852
Having no meaning in a primary key is usually a good thing.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29237
    
139

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ken Duncan
Ranch Hand

Joined: Apr 30, 2007
Posts: 39
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

Joined: Sep 12, 2007
Posts: 82
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.


Lynn Beighley<br />Author, Head First SQL
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HF SQL and Normalizing
 
Similar Threads
Update the whole info in database instead of one.
Primary key and update method strange issue
ATG Framework
JDBC Callable Statement JConnect2 Returning null resultset
Problem with update data to database