Database based on data one-to-one, one-to-many, many-to-many relationship design

Source: Internet
Author: User
Tags unique id

To do a project, must be the database design! In the learning stage, the basic is a single table. However, in the actual development process, one-to-many, many-to-many tables everywhere! Simple collation, one-to-many, many-to-many table how to design a tidy up ideas:

There are three types of correspondence between database entities: one-to- many, many-to-many.

One-to-one relationship example:

      • A student has a student file, or everyone has a unique ID number.

One-to-many relationship example:

      • A student belongs to only one class, but there are many students in a class.

Example of a many-to-many relationship:

      • A student can choose more than one course, and a class also has many students.

1. One-to-many relationship processing:

Learn about one-to-many through student and class issues:

Design database tables: Simply add a class number ID to the student table;

Note: In the database table in the beginner, or by adding the primary foreign key constraints, to avoid data deletion caused confusion!

2. Many-to-many relationship processing:

Learn how to handle many-to-many problems by choosing a course for students:

It doesn't work to add a field to a table in many pairs of Dozzong, so when dealing with many-to-many tables, you should consider building a relational table.

Cases:

Student Table: Curriculum: Relationship table:

Note: So for many-to-many tables, the relationship table establishes two tables of contact! When you set the primary foreign key for many-to-many tables, delete the constraint table contents and then delete the main table contents

Transfer from http://blog.csdn.net/witewater/article/details/53213285

Database based on data one-to-one, one-to-many, many-to-many relationship design

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.