What is a composite foreign key in mysql?

前端 未结 2 1309
死守一世寂寞
死守一世寂寞 2021-01-06 12:30

Seeing this term (composite foreign key) in the documentation for a framework I am using (yii). What is a composite foreign key (in a mySql database)?

(My guess

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-06 12:45

    A composite key consists of more than one attribute to uniquely identify an entity occurrence. This differs from a compound key in that one or more of the attributes, which make up the key, are not simple keys in their own right.

    For example, you have a database holding your CD collection. One of the entities is called tracks, which holds details of the tracks on a CD. This has a composite key of CD name, track number.

    enter image description here

    CD name in the track entity is a simple key, linking to the CD entity, but track number is not a simple key in its own right.

提交回复
热议问题