In database design what do n:m and 1:n mean?
Does it have anything to do with keys or relationships?
A one-to-many (1:N) relationship means a record in Table A can relate to zero, one, or many records in Table B. Many records in Table B can relate to one record in Table A.
“N” is the symbol used to denote normality. For example, 1M of hydrogen chloride gives 1M of hydrogen ions and 1M of chloride ions into the solution. 1M of hydrogen ions is equal to one equivalent of hydrogen ions.
In 1:n, 1 is the minimum cardinality, and n is the maximum cardinality. A relationship with cardinality specified as 1:1 to 1:n is commonly referred to as 1 to n when focusing on the maximum cardinalities. A minimum cardinality of 0 indicates that the relationship is optional.
m:n
is used to denote a many-to-many relationship (m
objects on the other side related to n
on the other) while 1:n
refers to a one-to-many relationship (1
object on the other side related to n
on the other).
1:n
means 'one-to-many'; you have two tables, and each row of table A may be referenced by any number of rows in table B, but each row in table B can only reference one row in table A (or none at all).
n:m
(or n:n
) means 'many-to-many'; each row in table A can reference many rows in table B, and each row in table B can reference many rows in table A.
A 1:n
relationship is typically modelled using a simple foreign key - one column in table A references a similar column in table B, typically the primary key. Since the primary key uniquely identifies exactly one row, this row can be referenced by many rows in table A, but each row in table A can only reference one row in table B.
A n:m
relationship cannot be done this way; a common solution is to use a link table that contains two foreign key columns, one for each table it links. For each reference between table A and table B, one row is inserted into the link table, containing the IDs of the corresponding rows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With