Many-to-many concepts: A student can learn several courses, a course can be several students study, stand in the perspective of a student to correspond to a number of courses, standing in the course there, corresponding to a number of students, so students and courses is a simple many-to-many relationship.
In the database we want to solve this many-to-many relationship application, first create a student table, such as
CREATE TABLE Stu (
stu_id int PRIMARY KEY,
Sty_name varchar (20)
);
And then create a curriculum
CREATE TABLE book (
book_id int PRIMARY KEY,
Book_name varchar (20)
);
Finally, we create an application table that sets the primary key of the student table and the main key of the curriculum to the Federated primary key of the application table.
CREATE TABLE Yingyong (
stu_id int primary KEY (stu_id,book_id),
book_id int
);
When we need to save "Zhang three learn Chinese" this data is just the Zhang San ID and the language of the ID can be saved, take the same time. This solves the many-to-many relational data in the database.
By the way: The table with the foreign key is the child table, and the parent table is its own primary key that is referenced by any child tables.