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

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

    A surrogate key is typically a numeric value. Within SQL Server, Microsoft allows you to define a column with an identity property to help generate surrogate key values.

    The PRIMARY KEY constraint uniquely identifies each record in a database table. Primary keys must contain UNIQUE values. A primary key column cannot contain NULL values. Most tables should have a primary key, and each table can have only ONE primary key.

    http://www.databasejournal.com/features/mssql/article.php/3922066/SQL-Server-Natural-Key-Verses-Surrogate-Key.htm

提交回复
热议问题