Using foreign key in Mysql is not as simple as Oracle and access. The following describes the issues that should be paid attention to during use:
Step 1: Create a table
First, open the command line window, enter the Mysql bin directory, select the corresponding database, and create the T_USER table:
Create table t_user (id int (11) not null auto_increment primary key, name VARCHAR (20), group_id int (10) type = InnoDB;
Create a T_PASSPORT table:
Create table t_passport (id int (11) not null auto_increment primary key, serial VARCHAR (20) type = InnoDB;
Note: The description of InnoDB is as follows:
InnoDB is the first MySQL engine to provide foreign key constraints. In addition to providing transaction processing, InnoDB also supports row locks and provides consistent read without locks like Oracle, it can increase the number of concurrent read users and improve performance without increasing the number of locks. That is to say, if you want to use foreign key constraints, the table type must be InnoDB, and mysql is MyISAM by default. This type does not support foreign key constraints.
[Content navigation] |
Page 1st: Mysql foreign Key Usage considerations |
Page 2nd: Mysql foreign Key Usage considerations |