Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of "n:m" and "1:n" in database design

In database design what do n:m and 1:n mean?

Does it have anything to do with keys or relationships?

like image 329
Abdullah Khan Avatar asked Aug 03 '10 14:08

Abdullah Khan


People also ask

What is 1:N relationship in DBMS?

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.

Is it 1:N or 1 M?

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

What is N in cardinality?

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.


2 Answers

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

like image 164
Matti Virkkunen Avatar answered Oct 09 '22 23:10

Matti Virkkunen


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.

like image 36
tdammers Avatar answered Oct 09 '22 23:10

tdammers