查找表的更易读的命名约定是什么?

发布于 2024-10-12 00:45:18 字数 551 浏览 3 评论 0原文

我们总是命名查找表 - 例如国家、城市、地区...等 - 如下:
EntityName_LKLK_EntityName(Countries_LK 或 LK_Countries)
但我想问是否有人有更好的查找表命名转换?

编辑
我们认为使用后缀或前缀来解决类似冲突:
如果我们有User表和UserTypes(ID-Name)查找表,并且UserUser之间存在多对多关系; UserTypes 使我们成为一个表,我们可以将其命名为 Types_For_User ,这可能会混淆 UserTypesUserTypesTypes_For_User 因此,我们希望使查找表 UserTypesUserTypesLK 一样,以便对所有人都显而易见

We always name lookup tables - such as Countries,Cities,Regions ... etc - as below :
EntityName_LK OR LK_EntityName ( Countries_LK OR LK_Countries )
But I ask if any one have more better naming conversions for lookup tables ?

Edit:
We think to make postfix or prefix to solve like a conflict :
if we have User tables and lookup table for UserTypes (ID-Name) and we have a relation many to many between User & UserTypes that make us a table which we can name it like Types_For_User that may make confusion between UserTypes & Types_For_User So we like to make lookup table UserTypes to be like UserTypesLK to be obvious to all

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

酷遇一生 2024-10-19 00:45:18

在决定需要“查找”绰号之前,您应该尝试理解为什么将某些表指定为“查找”而不是其他表。每个表本身应该代表一个实体。

当指定为“查找”的表的范围扩大并且不再被视为“查找”时,会发生什么情况?您要么更改表名称,这可能会很麻烦,要么保持原样,并且必须向每个人解释给定的表并不是真正的“查找”。

注释中提到的与连接表相关的常见场景。例如,假设用户可以有多个“类型”,这些“类型”在带有两个外键的联结表中表示。该表是否应该命名为User_UserTypes?对于这种情况,我首先会说我更喜欢在联结表上使用后缀 Member。所以我们会有UsersUserTypesUserTypeMembers。其次,“类型”这个词在这种情况下是非常通用的。 UserType 真的意味着角色吗?您使用的术语可能会带来很大的不同。如果UserTypes确实是角色,那么我们的表名称就变成UsersRolesRoleMembers,这看起来很清楚。

Before you decide you need the "lookup" moniker, you should try to understand why you are designating some tables as "lookups" and not others. Each table should represent an entity unto itself.

What happens when a table that was designated as a "lookup" grows in scope and is no longer considered a "lookup"? You are either left with changing the table name which can be onerous or leaving it as is and having to explain to everyone that a given table isn't really a "lookup".

A common scenario mentioned in the comments related to a junction table. For example, suppose a User can have multiple "Types" which are expressed in a junction table with two foreign keys. Should that table be called User_UserTypes? To this scenario, I would first say that I prefer to use the suffix Member on the junction table. So we would have Users, UserTypes, UserTypeMembers. Secondly, the word "type" in this context is quite generic. Does a UserType really mean a Role? The term you use can make all the difference. If UserTypes are really Roles, then our table names become Users, Roles, RoleMembers which seems quite clear.

荒岛晴空 2024-10-19 00:45:18

这里有两个关于是否使用前缀或后缀的问题。

  1. 在排序的表列表中,您希望 LK 表在一起还是希望与 EntityName 相关的所有表一起出现

  2. 在自动完成的环境中编程时,您是否可能想要键入“LK”来获取表列表或 EntityName 的开头?

我认为两者都有争议,但我会选择从 EntityName 开始。

Here are two concerns for whether to use a prefix or suffix.

  1. In a sorted list of tables, do you want the LK tables to be together or do you want all tables pertaining to EntityName to appear together

  2. When programming in environments with auto-complete, are you likely to want to type "LK" to get the list of tables or the beginning of EntityName?

I think there are arguments for either, but I would choose to start with EntityName.

折戟 2024-10-19 00:45:18

每个表都可以成为查找表。
考虑一个人是发票表中的一个查找。
所以在我看来,表应该只命名为(单数)实体名称,例如人员、发票。

您真正想要的是列名称和约束的标准,例如

FK_Invoice_Person (in table invoice, link to person)
PersonID or Person_ID (column in table invoice, linking to entity Person)

在一天结束时,这完全取决于个人偏好(如果您可以指定它)或团队标准。

更新

如果您的查找仅与实体相关,例如 Invoice_Terms,它是从 4 个场景的列表中进行查找,那么您可以将其命名为 Invoice_LK_Terms,这将使其按“发票”下分组的名称显示。另一种方法是使用一个查找表来进行简单的单值查找,由它所针对的函数(表+列)分隔,例如

Lookups
Table | Column | Value

Every table can become a lookup table.
Consider that a person is a lookup in an Invoice table.
So in my opinion, tables should just be named the (singular) entity name, e.g. Person, Invoice.

What you do want is a standard for the column names and constraints, such as

FK_Invoice_Person (in table invoice, link to person)
PersonID or Person_ID (column in table invoice, linking to entity Person)

At the end of the day, it is all up to personal preference (if you can get away with dictating it) or team standards.

updated

If you have lookups that pertain only to entities, like Invoice_Terms which is a lookup from a list of 4 scenarios, then you could name it as Invoice_LK_Terms which would make it appear by name grouped under Invoice. Another way is to have a single lookup table for simple single-value lookups, separated by the function (table+column) it is for, e.g.

Lookups
Table | Column | Value
怀念你的温柔 2024-10-19 00:45:18

只有一种类型的表,我不认为有任何充分的理由将某些表称为“查找”表。使用对每个表都适用的命名约定。

There is only one type of table and I don't believe there is any good reason for calling some tables "lookup" tables. Use a naming convention that works equally for every table.

花桑 2024-10-19 00:45:18

表命名约定可以提供帮助的领域之一是环境之间的数据迁移。我们经常必须移动查找表中的数据(这限制了可能出现在其他表中的值)以及架构更改,因为这些允许的值列表发生了变化。目前,我们没有以不同的方式命名查找表,但我们正在考虑这样做,以防止迁移人员询问“哪些表又是查找表?”每次。

One area where table naming conventions can help is data migration between environments. We often have to move data in lookup tables (which constrain values which may appear in other tables) along with schema changes, as these allowed value lists change. Currently we don't name lookup tables differently, but we are considering it to prevent the migration guy asking "which tables are lookup tables again?" every time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文