开发者

Surrogate foreign key

开发者 https://www.devze.com 2023-01-15 02:09 出处:网络
Oki so I have two tables:开发者_Go百科person and person_email PERSON ------ id (PK) person_code (Unique key 1)

Oki so I have two tables: 开发者_Go百科person and person_email

PERSON
------
id (PK)
person_code (Unique key 1)
person_type (Unique key 1)
surname
forename

PERSON_EMAIL
------------
id (PK)
person_id (Unique key 1) (references person(id))
email_address (Unique key 1)

Is this correct??

or should it be:

PERSON_EMAIL
------------
id (PK)
person_id (references person(id))
person_code (Unique key 1)
person_type (Unique key 1)
email_address (Unique key 1)


Your second suggestion includes both the unique identifiers of the PERSON table. If you try to do this, sooner or later you will find these identifiers indicate two different rows. Furthermore, changing the person_code or person_type in the PERSON table would then require a matching update of the PERSON_EMAIL table. For these reasons, I would suggest your first version is better.

0

精彩评论

暂无评论...
验证码 换一张
取 消