Prior to the use of SQL statements with the main foreign Key association, now with the visualization of the phpMyAdmin feel more convenient, but in the master foreign key constraints when the operation is not found in ten. Search on the internet is also a variety of strange, are said to be very obscure, a lot of said need to use Insert SQL statement, actually do not need to look at the steps:
I have created two tables:
Table 1:class1 (Main table)
Table II: Class2: (Schedule)
At this point I want to Class1 in the name and Class2 among the data_name to be related, this time we need to note the points:
First: The foreign key of the main table can have multiple, the foreign key and the primary key of the main table can be duplicated, but the foreign key must be the primary key of the schedule, and the type must be the same
The second: Two tables must be of the InnoDB engine, which can be set when the table is created:
Of course, even if we set up a table, it doesn't matter, it can be set up:
This time in the table you can see that there is an associated view, may be related to the version, some will be in
This place appears the relationship to view;
Click:
Perfect
How to create a foreign key constraint using phpMyAdmin