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