Privacy Policy Cookie Policy Terms and Conditions Natural key - Wikipedia, the free encyclopedia

Natural key

From Wikipedia, the free encyclopedia

In relational model database design, a natural key is a candidate key that has a logical relationship to the attributes within that row.

The main advantage of a natural key over a surrogate key, which has no such logical relationship, is that it already exists; there is no need to add a new, unnatural column to your schema.

The main disadvantage of choosing a natural key is that it may need to change if your business requirements change. For example, if you have chosen CustomerNumber as the primary key for a customer, and, subsequently, CustomerNumber becomes alphanumeric instead of numeric, then as well as changing the type of the column, you will need to make changes to all other tables where CustomerNumber is used as a foreign key.

[edit] External links

In a well-designed SQL engine, the values of a natural key appear only once in physical storage and they are referenced when they are used as foreign keys. The structural mechanisms for such referencing vary; Sybase SQL Anywhere uses pointer chains, the SAND engine uses compressed bit vectors, hashing is another way and so forth.

Older SQL engines, which are based on file systems, physically repeat the value in the FOREIGN KEY column and depend on procedural mechanisms to keep them aligned. Treating each table as if it were a separate file instead of implementing the schema as an interrelated whole can make changing the structure of a key very expensive.

Natural keys need three characteristics.

1) Uniqueness. This is the definition of any key. It cannot be NULL because NULLs lack uniqueness.

2) Validation. In the relational model, attributes are scalar values drawn from a domain that has rules. For example, if I see “2006-02-31” as a date data type, I know that it is wrong. Likewise, check digits and regular expressions can guard against false key values.

3) Verification. The key has to identify a real entity and we need a mechism to verify it. For example, if I have a VIN (Vehicle Identification Number), does such a vehicle actually exists? I can go on-line and ask the manufacturer, the Department of Motor Vehicles or an automobile website if this VIN was really used. If I have a (longitude, latitude) pair, I use a GPS or a globe to verify it directly, and so forth.

Static Wikipedia 2006 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr -
 
ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext -
fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz -
 
ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky -
la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn -
 
na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt -
qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl -
 
ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh -
yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -