Member Avatar for [NOPE]FOREVER

Can somebody please explain exatly what surrogate, natural and candidate keys are and how they differentate from each other?

Thankyou

joyc123 commented: gOOD QUESTION +0

A canidate key is any column in the data that can be used to uniquely identify the rows. For example if you had an employee table that included the company's employee number for each person and each person's social security number, both of those would be canidate keys to be actual keys.
A natural key is one that directly relates to the data. In the example above both would be natural keys if used as they both come from the data itself.
A surrogate key is one that is created for the data to provide uniqueness. Creating an identity column, a GUID or an auto incrementing primary key are all exmaples because they make each row unique but aren't a natural part of the data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.