简体   繁体   English

多变量依赖表的命名约定MySQL

[英]Naming Conventions for Multivariable Dependency Tables MySQL

Conventions for normalized databases rule that the best practice for dealing with multivariable dependencies is spinning them off into their own table with two columns. 规范化数据库的约定规定,处理多变量依赖项的最佳做法是将它们分解为两列的表。 One column is the primary key of the original table (for example, customer name, of which there is one), while the other is the value with has multiple values (for example, email or phone- the customer could have multiple of these). 一列是原始表的主键(例如,客户名称,其中有一个),而另一列是具有多个值的值(例如,电子邮件或电话,客户可以拥有多个) 。 Together these two columns constitute the primary key for the spun off table. 这两个列共同构成了分离表的主键。

However, when building normalized databases, I often find naming these spun off tables troublesome. 但是,在构建规范化数据库时,我经常发现将这些拆分表命名为麻烦的事情。 It's hard to come up with a meaningful names for these tables. 很难为这些表提出一个有意义的名称。 Is there a standard way of identifying these tables as multivariable dependency tables that are meaningless without the presence of the other table? 有没有一种标准的方法可以将这些表识别为没有其他表就没有意义的多变量依赖表? Some examples I can think of (referencing the example above) are 'customer_phones' or 'customer_has_phones'. 我可以想到的一些示例(参考上面的示例)是“ customer_phones”或“ customer_has_phones”。 I don't think just 'phones' would be good, because that doesn't identify this table as related to and heavily dependent on the customers table. 我认为仅使用“电话”并不是一件好事,因为这并不能确定该表与customers表相关并且在很大程度上依赖于customers表。

In real life you end up running into a lot of combinations that vary a lot from each other. 在现实生活中,您最终会遇到许多彼此相差很大的组合。

Try to be as clear as possible in case someone else ends up inheriting your design. 尽量保持清晰,以防其他人最终继承您的设计。 I personally like to keep short names in the parent tables so they don't end up being super long whenever the relationship grows or spans off new children. 我个人喜欢在父表中保留短名称,这样在关系增长或扩展新孩子时,它们就不会变得太长。

For instance, if I have "Customer", "Subscriptions", "Product" tables I would end up naming their links like "Customer_Subscriptions" or "Subscriptions_Products" and such. 例如,如果我有“客户”,“订阅”,“产品”表,那么我最终将命名它们的链接,例如“ Customer_Subscriptions”或“ Subscriptions_Products”等。

Most of the time it just gets down to what works better for you in terms of maintainability. 在大多数情况下,它只是取决于在可维护性方面对您更有效的方法。

The convention we use is the name of the entity table, followed by the name of the attribute. 我们使用的约定是实体表的名称,后跟属性的名称。

In your example, if the entity table is customer , the name of the table for the repeating (multi-valued) attribute would be customer_phone or customer_phone_number . 在您的示例中,如果实体表是customer ,则重复(多值)属性的表的名称将为customer_phonecustomer_phone_number (We almost always name tables in the singular, based on the idea that we are naming what ONE tuple (row) represents. (eg a row in that table represents one occurrence of a phone number for a customer.) (基于我们要命名一个元组(行)代表的想法,我们几乎总是以单数形式命名表。(例如,该表中的一行代表一个客户的电话号码)。

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

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