-->
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.  [ 2 posts ] 
Author Message
 Post subject: History table, composite ID or single ID
PostPosted: Wed Mar 28, 2007 7:26 am 
Newbie

Joined: Tue Jan 17, 2006 9:48 pm
Posts: 16
In principle, we should avoid composite ID. I think there is a exception case: history table should apply composite ID.

For example, tOrder has a single PK: orderID. tOrderHistory has all tOrder's columns and one version column.

Everytime user update a record in tOrder, the old data will be inserted into tOrderHistory.

Should I add one more PK column to tOrderHistory, or just make a composite PK (orderID, version)?

I can not find any value of one more PK column for tOrderHistory. I always search tOrderHistory via orderID and version.
So I think composite ID is better than single ID in this case.

Am I correct?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 12:28 pm 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
The answer is "Yes and no". You could also implement this using a "ORDER_HISTORY_ID" which is a surrogate key and define constraints(reference, unique constraints) etc. on the table to ensure data integrity.
This would require an additional SQL in case you have the "generator" as "Sequence" to determine the "ORDER_HISTORY_ID".

In this case since the number of primary keys are just 2 you can go either way.

_________________
--------------
Don't forget to Rate the post


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.