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

后端 未结 6 1709
遇见更好的自我
遇见更好的自我 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 01:41

    I think Michelle Poolet describes it in a very clear way:

    A surrogate key is an artificially produced value, most often a system-managed, incrementing counter whose values can range from 1 to n, where n represents a table's maximum number of rows. In SQL Server, you create a surrogate key by assigning an identity property to a column that has a number data type.

    http://sqlmag.com/business-intelligence/surrogate-key-vs-natural-key

    It usually helps you use a surrogate key when you change a composite key with an identity column.

提交回复
热议问题