• 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

Practical use of Unique Key

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Nitin Nigam
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One good example. Social Security number. While it should be unique, it should not be a Primary Key.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic