SQL 我应该为将两个表映射在一起的表命名什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1813321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:35:15  来源:igfitidea点击:

What should I name a table that maps two tables together?

sqldatabasedatabase-designnaming-conventionsdata-modeling

提问by devuxer

Let's say I have two tables:

假设我有两个表:

Table: Color
Columns: Id, ColorName, ColorCode

Table: Shape
Columns: Id, ShapeName, VertexList

What should I call the table that maps color to shape?

我应该怎么称呼将颜色映射到形状的表格?

Table: ???
Columns: ColorId, ShapeId

回答by tosh

There are only two hard things in Computer Science: cache invalidation and naming things
-- Phil Karlton

只有两个在计算机科学坚硬的东西:缓存失效和命名的事情
-菲尔Karlton

Coming up with a good name for a table that represents a many-to-manyrelationship makes the relationship easier to read and understand. Sometimes finding a great name is not trivial but usually it is worth to spend some time thinking about.

为代表many-to-many关系的表起一个好名字会使关系更容易阅读和理解。有时找到一个好名字并非易事,但通常值得花一些时间思考。

An example: Readerand Newspaper.

一个例子:ReaderNewspaper

A Newspaperhas many Readersand a Readerhas many Newspapers

ANewspaper有很多Readers,AReader有很多Newspapers

You could call the relationship NewspaperReaderbut a name like Subscriptionmight convey better what the table is about.

您可以调用这种关系,NewspaperReader但像这样的名称Subscription可能会更好地传达表格的内容。

The name Subscriptionalso is more idiomatic in case you want to map the table to objects later on.

Subscription如果您想稍后将表映射到对象,该名称也更加惯用。

The convention for naming many-to-manytables is a concatenation of the names of both tables that are involved in the relation. ColourShapewould be a sensible default in your case. That said, I think Nick D came up withtwo great suggestions: Styleand Texture.

命名many-to-many表的约定是将关系中涉及的两个表的名称串联起来。ColourShape在您的情况下,这将是一个明智的默认值。也就是说,我认为 Nick D提出了两个很好的建议:StyleTexture.

回答by Nick Dandoulakis

How about ColorShapeMapor Styleor Texture.

ColorShapeMapStyleTexture怎么样。

回答by Bill Karwin

Interesting about half of the answers give a general term for any table that implements a many-to-many relationship, and the other half of the answers suggest a name for this specific table.

有趣的是,大约一半的答案为实现多对多关系的任何表提供了一个通用术语,而另一半的答案建议了该特定表的名称。

I called these tables intersections tablesgenerally.

我一般称这些表为交叉表

In terms of naming conventions, most people give a name that is an amalgam of the two tables in the many-to-many relationship. So in this case, "ColorShape" or "ShapeColor." But I find this looks artificial and awkward.

在命名约定方面,大多数人给出的名称是多对多关系中两个表的混合物。所以在这种情况下,“ ColorShape”或“ ” ShapeColor。但我觉得这看起来很不自然而且很尴尬。

Joe Celko recommends in his book "SQL Programming Style" to name these tables in some natural language manner. For instance, if a Shape is colored by a Color, then name the table ColoredBy. Then you could have a diagram that more or less reads naturally like this:

Joe Celko 在他的“SQL 编程风格”一书中建议以某种自然语言方式命名这些表。例如,如果 Shape 由 Color 着色,则命名 table ColoredBy。然后你可以有一个或多或少看起来像这样自然的图表:

Shape <-- ColoredBy --> Color

Conversely, you could say a Color colors a Shape:

相反,您可以说颜色为形状着色:

Color <-- Colors --> Shape

But this looks like the middle table is the same thing as Colorwith a plural naming convention. Too confusing.

但这看起来中间表Color与复数命名约定相同。太混乱了。

Probably most clear to use the ColoredBynaming convention. Interesting that using the passive voice makes the naming convention more clear.

使用ColoredBy命名约定可能最清楚。有趣的是,使用被动语态使命名约定更加清晰。

回答by OMG Ponies

Name the table whatever you like, as long as it is informative:

随意命名表格,只要它提供信息即可:

COLOR_SHAPE_XREF

From a model perspective, the table is called a join/corrollary/cross reference table. I've kept the habit of using _XREFat the end to make the relationship obvious.

从模型的角度来看,该表称为连接/关联/交叉引用表。我一直保持_XREF在最后使用的习惯,以使关系显而易见。

回答by Ed Guiness

This is an Associative Entityand is quite often significant in its own right.

这是一个关联实体,并且本身通常很重要。

For example, a many to many relationship between TRAINS and TIMES gives rise to a TIMETABLE.

例如,TRAINS 和TIMES 之间的多对多关系产生了一个TIMETABLE。

If there's no obvious new entity (such as timetable) then the convention is to run the two words together, giving COLOUR_SHAPE or similar.

如果没有明显的新实体(例如时间表),那么约定是将这两个词放在一起,给出 COLOUR_SHAPE 或类似的。

回答by Ed Guiness

A mapping table is what this is usually called.

映射表就是通常所说的。

ColorToShape
ColorToShapeMap

回答by Dafydd Rees

I've worked with DBAs that call it a join table.

我曾与 DBA 合作过,他们将其称为连接表

Colour_Shape is fairly typical - unless the relationship has an explicit domain-specific name.

Colour_Shape 是相当典型的 - 除非该关系具有明确的特定于域的名称。

回答by priyanka.sarkar

Junction table

Junction table

ORBridge Table

或者Bridge Table

ORJoin Table

或者Join Table

ORMap Table

或者Map Table

ORLink Table

或者Link Table

ORCross-Reference Table

或者Cross-Reference Table

This comes into use when we go for many-to-many relationships where the keys from both the tables forms the composite primary key of the junction table.

当我们处理多对多关系时,这会派上用场,其中来自两个表的键构成联结表的复合主键。

回答by Bill the Lizard

I usually hear that called a Junction Table. I name the table by what it joins, so in your case either ColorShape, or ShapeColor. I think it makes more sense for a Shape to have a color than for a Color to have a shape, so I would go with ShapeColor.

我通常听到称为连接表。我根据它连接的内容命名表格,所以在你的情况下,要么是 ColorShape,要么是 ShapeColor。我认为 Shape 有颜色比 Color 有形状更有意义,所以我会选择ShapeColor.

回答by Neil N

Intermediate Tableor a Join Table

中间表连接表

I would name it "ColorShapes" or "ColorShape", depending on your preference

我会根据您的喜好将其命名为“ColorShapes”或“ColorShape”