Deciding between an artificial primary key and a natural key for a Products table

前端 未结 10 1306
粉色の甜心
粉色の甜心 2020-11-29 02:22

Basically, I will need to combine product data from multiple vendors into a single database (it\'s more complex than that, of course) which has several tables that will need

10条回答
  •  孤城傲影
    2020-11-29 03:18

    A surrogate key (auto increment INT field) will uniquely identify a row in the table. On the other hand, a Unique Natural key (productName) will prevent duplicate product data from entering the table.

    With a unique Natural key field, two or more rows can never have same data.

    With a surrogate key field, Rows can be unique because of the auto increment INT field but data in rows will not be unique because the surrogate key has no relation to the data.

    Lets take an example of a User table, the table's Natural key field (userName) will prevent same user from registering twice but the auto increment INT field (userId) will not.

提交回复
热议问题