Description of the database design and many-to-many application scenarios?

Do a project, it is indispensable necessity database design! In the learning phase, basically single table. However, in the actual development process, one-to-many tables everywhere! Simple and tidy, one-to-many table to sort out how to design ideas:

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

 

       One relationship Example:

    • A student archival material corresponds to a student, or each person has a unique ID number.

 

 

       Many relationship example:

    • A student belongs to only one class, but a class a number of students.

 

 

       Many relationship example:

    • Students can choose a multi-course, a course also a number of students.

 

 

 

 

 

First, the realization relationship

    In the entity-relationship model, we know that there are three relationships: one to one, one to many, many to many . This is only a conceptual relationship, but in a real relational database, we have only foreign keys ,

These three relationships are not, then we'll talk about in a relational database management system, how to achieve these three relationships.

 

Many

    Here to explain many, because this relationship is the simplest. And many-to-many is one thing, so I will not mention many-word. Is a concept many object A will correspond to a plurality of objects B,

From the angle B of view, an object B corresponds to only one object A. For example, classes and students is one to many relationship. A corresponding number of students in class, a student will only be for a class.

 

    The reason for that is simple-to-many relationship, because the RDBMS [foreign keys] in fact represent many relationship. For many relationship, we only need to create foreign key "one" to "many" of the table ,

The "one" side of the table do not need to make any changes. For example, students in the class relations said before. Class table unchanged, increase student table as a foreign key Id class.

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/Rivend/p/12089592.html