Home > Database > Mysql Tutorial > body text

N-ary relationship in database

PHPz
Release: 2023-08-22 08:41:08
forward
1507 people have browsed it

N-ary relationship in database

Relationship is an important part of any entity relationship diagram as it shows the relationship between two different entities. In an n-ary relationship, n represents the number of entities in the relationship. It can be any value, but the most common relationships are unary, binary, and ternary relationships, where the number of entities is one, two, and three respectively.

More information about unary, binary and ternary relationships is as follows:

Uniary Relationship

When there is a relationship between two entities of the same type, is called a unary or recursive relationship. This means that relationships are between different instances of the same entity type. Some examples of uniary relationships are as follows:

One-to-one uniary relationship

N-ary relationship in database

A person can only be married to one person at a time. So this is a recursive relationship between the entity person and itself. This is a one-to-one recursive relationship because one person is married to one person.

One-to-many one-element relationship

N-ary relationship in database

One employee can supervise multiple employees. So this is a recursive relationship between the entity employee and itself. This is a one-to-many recursive relationship because one employee supervises multiple employees.

Binary Relationship

When there is a relationship between two different entities, it is called a binary relationship. Some examples of binary relationships are as follows:

One-to-one binary relationship

N-ary relationship in database

Each employee has only one ID card. So this is a one to one binary relationship where 1 employee has 1 ID card.

Many to One Binary Relationship

N-ary relationship in database

Many employees work in one department. So this is a many to one binary relationship where many employees work in one department.

Many-to-Many Binary Relationship

N-ary relationship in database

A book can have multiple authors, or multiple authors may write a book. Therefore, there is a many-to-many relationship between books and authors, i.e. many books have many authors.

Ternary relationship

When there is a relationship between three different entities, it is called a ternary relationship. An example of a ternary relationship is as follows:

N-ary relationship in database

In this example, there is a ternary relationship between doctor, patient, and drug.

The above is the detailed content of N-ary relationship in database. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!