Foreign keys vs secondary keys

前端 未结 3 992
温柔的废话
温柔的废话 2021-01-04 22:58

I used to think that foreign key and secondary key are the same thing.

After Googling the result are even more confusing, some consider them to be the same, others s

3条回答
  •  攒了一身酷
    2021-01-04 23:51

    "Secondary key" is not a term I'm familiar with. It doesn't appear in the index of Database Design for Mere Mortals and I don't remember it in Pro SQL Server 2012 Relational Database Design and Implementation (my two "goto" books for database design). It also doesn't appear in the index for SQL for Smarties. It sounds like its not an actual term at all.

    I've always used the term "candidate key".

    A candidate key is a way to uniquely identify an entity. You identify all the candidate keys during the design phase of a database system. During the implementation phase, you will decide on a primary key: either one of the candidate keys or an artificial key. The primary key will probably be implemented with a primary key constraint; the candidate keys will probably be implemented with unique constraints.

    A foreign key is an instance of one entity's candidate key in another entity, representing a relationship between the two entities. It will probably be implemented with a foreign key constraints.

提交回复
热议问题