文本中的实体关系表示法

发布于 2024-08-06 08:44:22 字数 231 浏览 5 评论 0原文

实体关系是否有标准(非图形)表示法?

现在我正在使用我自己的简陋符号:

  • 用户>>照片,(1-多)
  • 用户> Profile , (1-1 hasOne)
  • Profile <用户 , (1-1 属于)
  • 照片 <<用户 , (many-1 属于)
  • 照片 <>标签,(多对多)

Is there a standard (non-graphical) notation for Entity Relationships?

right now I'm using my own janky notation:

  • User >> Photo , (1-many)
  • User > Profile , (1-1 hasOne)
  • Profile < User , (1-1 belongsTo)
  • Photo << User , (many-1 belongsTo)
  • Photo <> Tag , (many-many)

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

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

发布评论

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

评论(3

月寒剑心 2024-08-13 08:44:22

差不多十年后,我也很难找到明文标准。这是我到目前为止所发现的(不过,公平警告,它主要是图形标准,恰好在文本中运行良好)。

首先,描述对象之间关系基数的常用术语是“多重性”。

这种关联关系表明(至少)两个相关类之一引用了另一个类。这种关系通常被描述为“A has a B”(母猫有小猫,小猫有母猫)。

尽管相当多的来源也使用术语“基数”。
关于多重性与基数这个SO问题的差异有一些很好的答案。我发现这个非常简洁:

...重数由下基数和上基数组成。基数是一个集合中有多少个元素。因此,重数告诉您该集合允许的最小和最大成员。

UML 的多重性表示法

UML 的 多重表示法 在文本中效果很好。

+--------------+--------+-----------------------------------------+
| Multiplicity | Option |               Cardinality               |
+--------------+--------+-----------------------------------------+
| 0..0         | 0      | Collection must be empty                |
| 0..1         |        | No instances or one instance            |
| 1..1         | 1      | Exactly one instance                    |
| 0..*         | *      | Zero or more instances                  |
| 1..*         |        | At least one instance                   |
| 5..5         | 5      | Exactly 5 instances                     |
| m..n         |        | At least m but no more than n instances |
+--------------+--------+-----------------------------------------+

这似乎有一些变体:

  • 微软的关系表示法

    <前><代码>+--------------------------------+--------- ------------+
    |多重性|基数 |
    +--------------------------------+---------------------------- ------+
    | * |一比零或更多|
    | 1..* | 1..*一对一或多对 |
    | 0..1 | 0..1一比零还是一|
    | 1 |正好一个 |
    |用破折号分隔的两个数字 |范围 |
    +--------------------------------+---------------------------- ------+

  • IBM 的

    <前><代码>+------+--------------------+---------------------------- ----------------+
    |玫瑰|软件架构师|描述 |
    +------+--------------------+--------------------- ----------+
    | n | * |无限数量的实例 |
    | 1 | 1 |恰好 1 个实例 |
    | 0..n | 0..n | * | 0 个或多个实例 |
    | 1..n | 1..n | 1,,* | 1 个或多个实例 |
    | 0..1 | 0..1 0..1 | 0..1 0 或 1 个实例 |
    +------+--------------------+--------------------- ----------+

  • Smartdraw 的马丁风格

陈风格

来自 我读到的陈式是“原始格式”。我通常将其以文本形式表示为:

+----------+--------------+
| Notation | Description  |
+----------+--------------+
| 1:1      | One to One   |
| 1:N      | One to Many  |
| N:1      | Many to One  |
| M:N      | Many to Many |
+----------+--------------+

IDEF1X 和

其他IDEF1x(NIST 标准):

IDEF1X 是一种设计关系数据库的方法,其语法旨在支持开发概念模式所需的语义构造。

这似乎描述了Min-Max / ISO notation(英文链接目前为已损坏,但维基百科的 实体关系模型文章 其中还列出了一些其他样式的图形符号,其中一些是文本友好。

输入图像描述这里

德语有关 (min,max) 表示法的文章 还有一个有用的表格比较 UML、Chen、(min,max) 和 MC(修改陈)

+----------------------+-----------------+---------------------------------+-------------+-----------------+----------------------+
| (min,max) [Entity 1] | [UML, Entity 1] |          Chen-Notation          | MC-Notation | [UML, Entity 2] | (min,max) [Entity 2] |
+----------------------+-----------------+---------------------------------+-------------+-----------------+----------------------+
| (0,1)                | 0..1            | 1:1                             | c:c         | 0..1            | (0,1)                |
| (0,N)                | 0..1            | 1:N                             | c:mc        | 0..*            | (0,1)                |
| (0,N)                | 1..1            | 1:N + total participation       | 1:mc        | 0..*            | (1,1)                |
| (0,N)                | 0..*            | M:N                             | mc:mc       | 0..*            | (0,N)                |
| (1,1)                | 0..1            | total participation + 1:1       | c:1         | 1..1            | (0,1)                |
| (1,N)                | 0..1            | total participation + 1:N       | c:m         | 1..*            | (0,1)                |
| (1,1)                | 1..1            | total part. + 1:1 + total part. | 1:1         | 1..1            | (1,1)                |
| (1,N)                | 1..1            | total part. + 1:N + total part. | 1:m         | 1..*            | (1,1)                |
| (1,N)                | 0..*            | total participation + M:N       | mc:m        | 1..*            | (0,N)                |
| (1,N)                | 1..*            | total part. + M:N + total part. | m:m         | 1..*            | (1,N)                |
+----------------------+-----------------+---------------------------------+-------------+-----------------+----------------------+

Almost 10 years later and I've also had a hard time finding plaintext standards. Here's what I've found so far (fair warning though, it's mostly graphical standards that happen to work well in text).

First, the common term for describing the cardinality of a relationship between objects is "multiplicity".

This association relationship indicates that (at least) one of the two related classes make reference to the other. This relationship is usually described as "A has a B" (a mother cat has kittens, kittens have a mother cat).

Though a considerable number of sources also use the term "cardinality".
There's a few good answers about the difference on this SO question about Multiplicity vs Cardinality. I found this one to be pretty succinct:

...a multiplicity is made up of a lower and an upper cardinality. A cardinality is how many elements are in a set. Thus, a multiplicity tells you the minimum and maximum allowed members of the set.

UML's Multiplicity Notation

UML's multiplicity notation works well in text.

+--------------+--------+-----------------------------------------+
| Multiplicity | Option |               Cardinality               |
+--------------+--------+-----------------------------------------+
| 0..0         | 0      | Collection must be empty                |
| 0..1         |        | No instances or one instance            |
| 1..1         | 1      | Exactly one instance                    |
| 0..*         | *      | Zero or more instances                  |
| 1..*         |        | At least one instance                   |
| 5..5         | 5      | Exactly 5 instances                     |
| m..n         |        | At least m but no more than n instances |
+--------------+--------+-----------------------------------------+

There seem to be a few variations of this:

  • Microsoft's Relational Notation

    +---------------------------------+---------------------+
    |          Multiplicity           |     Cardinality     |
    +---------------------------------+---------------------+
    | *                               | One to zero or more |
    | 1..*                            | One to one or more  |
    | 0..1                            | One to zero or one  |
    | 1                               | Exactly one         |
    | Two numbers separated by a dash | a range             |
    +---------------------------------+---------------------+
    
  • IBM's

    +------+--------------------+-------------------------------+
    | Rose | Software Architect |          Description          |
    +------+--------------------+-------------------------------+
    | n    | *                  | Unlimited number of instances |
    | 1    | 1                  | Exactly 1 instance            |
    | 0..n | *                  | 0 or more instances           |
    | 1..n | 1,,*               | 1 or more instances           |
    | 0..1 | 0..1               | 0 or 1 instances              |
    +------+--------------------+-------------------------------+
    
  • Smartdraw's Martin Style

Chen Style

From what I've read Chen style is the "original format". I commonly see this expressed in text as:

+----------+--------------+
| Notation | Description  |
+----------+--------------+
| 1:1      | One to One   |
| 1:N      | One to Many  |
| N:1      | Many to One  |
| M:N      | Many to Many |
+----------+--------------+

IDEF1X and Others

There's IDEF1x (a NIST standard):

IDEF1X is a method for designing relational databases with a syntax designed to support the semantic constructs necessary in developing a conceptual schema.

That seems to describe the Min-Max / ISO notation (the English link is currently broken but here's a German article) referenced by Wikipedia's Entity–relationship model article which also lists a few other styles of graphical notations, some of which are text-friendly.

enter image description here

The German language article on (min,max) notation also has a useful table comparing UML, Chen, (min,max) and MC (Modified Chen):

+----------------------+-----------------+---------------------------------+-------------+-----------------+----------------------+
| (min,max) [Entity 1] | [UML, Entity 1] |          Chen-Notation          | MC-Notation | [UML, Entity 2] | (min,max) [Entity 2] |
+----------------------+-----------------+---------------------------------+-------------+-----------------+----------------------+
| (0,1)                | 0..1            | 1:1                             | c:c         | 0..1            | (0,1)                |
| (0,N)                | 0..1            | 1:N                             | c:mc        | 0..*            | (0,1)                |
| (0,N)                | 1..1            | 1:N + total participation       | 1:mc        | 0..*            | (1,1)                |
| (0,N)                | 0..*            | M:N                             | mc:mc       | 0..*            | (0,N)                |
| (1,1)                | 0..1            | total participation + 1:1       | c:1         | 1..1            | (0,1)                |
| (1,N)                | 0..1            | total participation + 1:N       | c:m         | 1..*            | (0,1)                |
| (1,1)                | 1..1            | total part. + 1:1 + total part. | 1:1         | 1..1            | (1,1)                |
| (1,N)                | 1..1            | total part. + 1:N + total part. | 1:m         | 1..*            | (1,1)                |
| (1,N)                | 0..*            | total participation + M:N       | mc:m        | 1..*            | (0,N)                |
| (1,N)                | 1..*            | total part. + M:N + total part. | m:m         | 1..*            | (1,N)                |
+----------------------+-----------------+---------------------------------+-------------+-----------------+----------------------+
就是爱搞怪 2024-08-13 08:44:22

为什么不使用与 ER 图中相同的内容:

  • 用户 1-n 照片
  • 用户 1-1 个人资料
  • 照片 n-1 用户

等等。 但我从未听说过官方明文标准。

Why not use the same than in ER-Diagramms:

  • User 1-n Photos
  • User 1-1 Profile
  • Photo n-1 User

and so on. But I never heard of an official plaintext standart.

傲世九天 2024-08-13 08:44:22

有软件可以将纯文本描述转换为可视化 ER 图。

例如 erd 使用以下符号:

Cardinality    Syntax
0 or 1         ?
exactly 1      1
0 or more      *
1 or more      +

示例:

Person *--1 `Birth Place`
Artist +--? PlatinumAlbums

另请检查此 类似工具列表

然而,这些都不能称为标准。

There is software available that transforms plain text descriptions into visual ER diagrams.

For instance erd uses the following notation:

Cardinality    Syntax
0 or 1         ?
exactly 1      1
0 or more      *
1 or more      +

Examples:

Person *--1 `Birth Place`
Artist +--? PlatinumAlbums

Check also this list of similar tools.

However, none of these could be called a standard.

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