1

I was searching about natural keys and found somewhere that they are made from the data that exist outside the current database..I am not getting this ..how a key can be built using outside data...? If its using foreign key than what is the difference between them.?

Qazazaz
  • 120
  • 1
  • 1
  • 14
  • It's in the database, but it corresponds to data in the real world. See https://en.wikipedia.org/wiki/Natural_key – Barmar Sep 04 '15 at 09:25
  • The example it gives is a social security number. This uniquely identifies a person, so you could use that in a database of people instead of creating your own unique key. – Barmar Sep 04 '15 at 09:26
  • (Although SSNs are also good examples of why Natural Keys can .. fail as keys. Even if there where no used duplicates, not everyone has an SSN.) – user2864740 Sep 04 '15 at 09:27
  • Social security number is inside the database? – Qazazaz Sep 04 '15 at 09:29
  • @Himanshu An SSN could be, sure. It was just used as an example of a Natural Key. Other examples (whether or not such are warranted for use as such, and some can quickly be pointed out as flawed) are Full Names, Phone Numbers, git SHA1s, SharePoint Solution GUIDs, Product SKUs, Customer Account Numbers, etc. Basically, if they key *comes* from an outside business rule or authority or *has meaning* external to the database it is a Natural Key. If the key *only* has meaning to the database relations then it's a Surrogate Key (usually an "auto increment" of sorts). – user2864740 Sep 04 '15 at 09:35
  • Thanks for help..."Basically, if they key comes from the outside" ..this means its not present in database ? If not present..then how can we use that outside data ? – Qazazaz Sep 04 '15 at 09:38
  • 1
    It is present in the database *when it is added*. Think up a number. Write it down on a piece of paper. Did the number change? The same is true for a Natural Key *value* when doesn't exist in the database but is then added. – user2864740 Sep 04 '15 at 09:39
  • Ok..I got it..thanks again.. :) – Qazazaz Sep 04 '15 at 09:41
  • See [this recent answer](http://stackoverflow.com/a/32151278/3404097). – philipxy Sep 05 '15 at 03:42

0 Answers0