开发者

What's more readable naming conventions for lookup tables?

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


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.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜