查找表的更易读的命名约定是什么?
我们总是命名查找表 - 例如国家、城市、地区...等 - 如下:EntityName_LK
或 LK_EntityName
(Countries_LK 或 LK_Countries)
但我想问是否有人有更好的查找表命名转换?
编辑:
我们认为使用后缀或前缀来解决类似冲突:
如果我们有User
表和UserTypes
(ID-Name)查找表,并且User
和User
之间存在多对多关系; UserTypes
使我们成为一个表,我们可以将其命名为 Types_For_User
,这可能会混淆 UserTypes
和 UserTypes
。 Types_For_User
因此,我们希望使查找表 UserTypes
与 UserTypesLK
一样,以便对所有人都显而易见
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在决定需要“查找”绰号之前,您应该尝试理解为什么将某些表指定为“查找”而不是其他表。每个表本身应该代表一个实体。
当指定为“查找”的表的范围扩大并且不再被视为“查找”时,会发生什么情况?您要么更改表名称,这可能会很麻烦,要么保持原样,并且必须向每个人解释给定的表并不是真正的“查找”。
注释中提到的与连接表相关的常见场景。例如,假设用户可以有多个“类型”,这些“类型”在带有两个外键的联结表中表示。该表是否应该命名为
User_UserTypes
?对于这种情况,我首先会说我更喜欢在联结表上使用后缀Member
。所以我们会有Users
、UserTypes
、UserTypeMembers
。其次,“类型”这个词在这种情况下是非常通用的。UserType
真的意味着角色吗?您使用的术语可能会带来很大的不同。如果UserTypes
确实是角色,那么我们的表名称就变成Users
、Roles
、RoleMembers
,这看起来很清楚。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 suffixMember
on the junction table. So we would haveUsers
,UserTypes
,UserTypeMembers
. Secondly, the word "type" in this context is quite generic. Does aUserType
really mean a Role? The term you use can make all the difference. IfUserTypes
are really Roles, then our table names becomeUsers
,Roles
,RoleMembers
which seems quite clear.这里有两个关于是否使用前缀或后缀的问题。
在排序的表列表中,您希望 LK 表在一起还是希望与 EntityName 相关的所有表一起出现
在自动完成的环境中编程时,您是否可能想要键入“LK”来获取表列表或 EntityName 的开头?
我认为两者都有争议,但我会选择从 EntityName 开始。
Here are two concerns for whether to use a prefix or suffix.
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
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.
每个表都可以成为查找表。
考虑一个人是发票表中的一个查找。
所以在我看来,表应该只命名为(单数)实体名称,例如人员、发票。
您真正想要的是列名称和约束的标准,例如
在一天结束时,这完全取决于个人偏好(如果您可以指定它)或团队标准。
更新
如果您的查找仅与实体相关,例如 Invoice_Terms,它是从 4 个场景的列表中进行查找,那么您可以将其命名为 Invoice_LK_Terms,这将使其按“发票”下分组的名称显示。另一种方法是使用一个查找表来进行简单的单值查找,由它所针对的函数(表+列)分隔,例如
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
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.
只有一种类型的表,我不认为有任何充分的理由将某些表称为“查找”表。使用对每个表都适用的命名约定。
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.
表命名约定可以提供帮助的领域之一是环境之间的数据迁移。我们经常必须移动查找表中的数据(这限制了可能出现在其他表中的值)以及架构更改,因为这些允许的值列表发生了变化。目前,我们没有以不同的方式命名查找表,但我们正在考虑这样做,以防止迁移人员询问“哪些表又是查找表?”每次。
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.