简体   繁体   English

SQL模式-默认为1:很多

[英]SQL Schema - Default of 1:Many

How can I specify the default value of a 1:Many relationship ... for example take a user that has 5 phone numbers ... I need to record the "preferred" phone number. 如何指定1:很多关系的默认值...例如,以一个拥有5个电话号码的用户...我需要记录“首选”电话号码。 Should I use an attribute on the phone_number record to indicate the preferred one - or have a attribute of the user record ( preferred_phone_number for example) that is the primary key from the phone_numbers table ? 我应该使用phone_number记录上的属性来指示首选的属性吗?还是应该使用用户记录的属性(例如, preferred_phone_number )作为phone_numbers表中的主键?

Thanks 谢谢

  1. User.preferred_phone : you have zero or one preferred numbers per user. User.preferred_phone :每个用户有零个或一个首选号码。

  2. Phone.is_preferred : you may have any amount of preferred numbers per user, without a way to choose the 'most preferred', and even 'preferred numbers' that no user relates to. Phone.is_preferred :每个用户可能有任意数量的首选号码,而无法选择没有用户关联的“最喜欢的号码”,甚至“首选号码”。

So I'd clearly stick with #1. 所以我显然会坚持第一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM