aspose file tools
The moose likes Oracle/OAS and the fly likes Practical use of Unique Key Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Products » Oracle/OAS
Reply Bookmark "Practical use of Unique Key" Watch "Practical use of Unique Key" New topic
Author

Practical use of Unique Key

Nitin Nigam
Ranch Hand

Joined: Jul 03, 2006
Posts: 129
Dear friends,
Can anybody tell me a real life scenario where one would need a unique key?
As far as my understanding of Normalization goes, i would not need a unique key if my tables are properly normalized. Because if i am having a unique key (There would always be a primary key), then the data in my table would not depend on a single column. So i need to normalize my table untill all the data is dependent upon one single column. And this will remove any possibility of having unique key in my table.

Please correct me if i am wrong.

Thanks in advance


Nothing is impossible; for those who doesnt have to do it themselves.
myjotting.blogspot.com
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17243
    
    1

There are many, many cases where you will have a unique column that is not a primary key. Sometimes business rules play in that decision, and also there are natural keys that you do not want to be primary key, because they have business logic, but you still need it to be unique.

For Primary keys, it is highly recommended to use a surrogate key. An int that gets generated from like a sequence table, then there is no business logic in the PK.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Nitin Nigam
Ranch Hand

Joined: Jul 03, 2006
Posts: 129
Recently i attended a technical interview and the interviewer was hell bent on asking a real life scenario where one would need the unique key. And i was unable to answer.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17243
    
    1

One good example. Social Security number. While it should be unique, it should not be a Primary Key.

Mark
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Practical use of Unique Key
 
Similar Threads
Update value of primary key impossible
retrieve blob data from mysql using jsp
connection factory
Table without Primary key
how to make the entry unique