What is the difference between a primary key and a surrogate key?

后端 未结 6 1705
遇见更好的自我
遇见更好的自我 2021-02-01 01:26

I googled a lot, but I did not find the exact straight forward answer with an example.

Any example for this would be more helpful.

6条回答
  •  北海茫月
    2021-02-01 02:03

    All keys are identifiers used as surrogates for the things they identify. E.F.Codd explained the concept of system-assigned surrogates as follows [1]:

    Database users may cause the system to generate or delete a surrogate, but they have no control over its value, nor is its value ever displayed to them.

    This is what is commonly referred to as a surrogate key. The definition is immediately problematic however because Codd was assuming that such a feature would be provided by the DBMS. DBMSs in general have no such feature. The keys are normally visible to at least some DBMS users as, for obvious reasons, they have to be. The concept of a surrogate has therefore morphed slightly in usage. The term is generally used in the data management profession to mean a key that is not exposed and used as an identifier in the business domain. Note that this is essentially unrelated to how the key is generated or how "artificial" it is perceived to be. All keys consist of symbols invented by humans or machines. The only possible significance of the term surrogate therefore relates how the key is used, not how it is created or what its values are.

    [1] Extending the database relational model to capture more meaning, E.F.Codd, 1979

提交回复
热议问题