The value "n: m" and "1: n" in the database design

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

Does it have anything to do with keys or relationships?

+47
database mysql foreign-keys relationship
Aug 03 '10 at 14:14
source share
7 answers

m:n used to denote a many-to-many relationship ( m objects on the other hand, associated with n on the other), and 1:n refers to a one-to-many relationship ( 1 object on the other hand, associated with n on the other )

+63
Aug 03 '10 at 14:17
source share

1: n means one to many; you have two tables, and each row of table A can refer to any number of rows in table B, but each row in table B can refer to only one row in table A (or none at all).

n: m (or n: n) means many-to-many; each row in table A can refer to many rows in table B, and each row in table B can refer to many rows in table A.

The 1: n ratio is usually modeled using a simple foreign key β€” one column in table A refers to a similar column in table B, usually the primary key. Since the primary key uniquely identifies exactly one row, many rows in table A can be referenced to this row, but each row in table A can only refer to one row in table B.

The n: m relationship cannot be performed in this way; a common solution is to use a link table containing two columns of the foreign key, one for each table associated with it. For each link between table A and table B, one row is inserted into the link table containing the identifiers of the corresponding rows.

+44
Aug 03 '10 at 14:20
source share

n: m β†’, if you don’t know both n and m, it’s just a lot for many, and it is represented by a bridge table between two other tables, such as

  -- This table will hold our phone calls. CREATE TABLE dbo.PhoneCalls ( ID INT IDENTITY(1, 1) NOT NULL, CallTime DATETIME NOT NULL DEFAULT GETDATE(), CallerPhoneNumber CHAR(10) NOT NULL ) -- This table will hold our "tickets" (or cases). CREATE TABLE dbo.Tickets ( ID INT IDENTITY(1, 1) NOT NULL, CreatedTime DATETIME NOT NULL DEFAULT GETDATE(), Subject VARCHAR(250) NOT NULL, Notes VARCHAR(8000) NOT NULL, Completed BIT NOT NULL DEFAULT 0 ) 

this is a bridge table for mapping between two tables

 CREATE TABLE dbo.PhoneCalls_Tickets ( PhoneCallID INT NOT NULL, TicketID INT NOT NULL ) 

One to large (1: n) is just one table that has a column as a primary key and another table that has this column as a foreign key relation

The type of product and product in which one product may have many products.

+5
Aug 03 '10 at 14:30
source share

In a relational database, all types of relationships are represented in the same way: as relationships. The candidate key of each relationship (and possibly other restrictions) determines which relationships are represented. 1: n and m: n are two types of binary relations:

 C {Employee*,Company} B {Book*,Author*} 

In each case, * denotes a key attribute. {Book, Author} is a composite key.

C is a relationship in which each employee works for only one company, but each company can have many employees (1: n): B is a relationship in which a book can have many authors, and the author can write many (m: n):

Please note that key restrictions ensure that each employee can be associated with only one company, while any combination of books and authors is allowed.

Other types of relationships are possible: n-ary (with more than two components); fixed power (m: n, where m and n are fixed constants or ranges); directed; and so on. William Kent in his book Data and Reality identifies at least 432 species - and that’s just for binary relationships. In practice, the binary ratios 1: n and m: n are very common and usually stand out as especially important when designing and understanding data models.

+3
Aug 03 '10 at 20:32
source share

To explain two concepts using an example, imagine that you have an order entry system for a bookstore. Displaying orders for items is a lot for many (n: m), because each order can have multiple items, and each item can be ordered in multiple orders. On the other hand, the search for customers and orders is one-on-one (1: n), because a customer can place several orders, but an order can never be more than one customer.

+2
Aug 03 '10 at 14:21
source share

Many to Many (n: m) One to Large (1: n)

+1
Aug 03 '10 at 14:17
source share

m: n refers to many relationships where 1: n means one to another relationship e.g. employee (number, name, Skillset) Skillset (identifier, skillname, qualification)

in this case, one employee can have many skills and ignore other cases, you can say that his ratio is 1: N

0
Feb 09 '17 at 9:27
source share



All Articles