Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Relation notation in text

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)
like image 579
cardflopper Avatar asked Dec 23 '22 08:12

cardflopper


2 Answers

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).

  • Wikipedia

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.

  • Jim L.

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)                |
+----------------------+-----------------+---------------------------------+-------------+-----------------+----------------------+
like image 133
Nick Frezynski Avatar answered Mar 20 '23 07:03

Nick Frezynski


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.

like image 39
theomega Avatar answered Mar 20 '23 05:03

theomega