-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Best practices? id versus composite key
PostPosted: Tue Mar 01, 2005 1:44 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
Hi,

This is a newbie question I guess.

I am not clear on when one should use a DB-generated id column versus a composite key. I mean, I can think up of specific instances where a table's primary key naturely *feels* like it should consist of multiple components. For example:

Table ImageDimension
- width
- height
- reference count

In the above case, I would assume one should use a composite key consisting of width and height because it feels natural that a dimension is uniquely defined by its width and height. We don't want to end up with two separate instances having the same width and height.

Does one only use the "id" approach when there is no clear concept of what the primary key should be? Please give me some tips on "best practices".

Thank you,
Gili


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 1:46 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
As a follow-up question, are there performance issues with picking one approach over the other? Should I not concern myself with that and instead focus on what makes sense from a design point of view?

Gili


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 3:19 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Don't use primary keys with a business meaning. If the business chanages you will be in trouble.

Use one of the technical key mechanisms your DBMS provides.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 10:32 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
ernst_pluess wrote:
Don't use primary keys with a business meaning. If the business chanages you will be in trouble.

Use one of the technical key mechanisms your DBMS provides.

HTH
Ernst


Is there *ever* a valid reason for using composite keys?

Gili


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 10:35 am 
Newbie

Joined: Mon Feb 16, 2004 11:28 pm
Posts: 16
In the hibernate in action book they strongly suggest using arbitrary sequences for primary key fields and to put unique indexes on surrogate keys(unique keys with business meaning).

Hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 11:03 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
javamac wrote:
In the hibernate in action book they strongly suggest using arbitrary sequences for primary key fields and to put unique indexes on surrogate keys(unique keys with business meaning).

Hope this helps.


Thanks Javamac!

I looked up the term surrogate keys and found this http://www.bcarter.com/intsurr1.htm which and http://www.dbmsmag.com/9805d05.html

It makes a more sense now.

Thank you,
Gili


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 5:44 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Quote:
Is there *ever* a valid reason for using composite keys?


If you have a legacy DB sometines you don't have an option.

HTH
Ernst


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.