Discover mysql foreign key example, include the articles, news, trends, analysis and practical advice about mysql foreign key example on alibabacloud.com
There's a thing that's been bothering me in my head, but it's not clear that it's going to hinder my progress. Do your own project demo can always use only one sheet ...
So today is still learning the next foreign key hope to understand some ...
Baidu on the role of the search foreign key "to maintain data integrity, c
(Restrict foreign key changes in appearance), SET null (null value), set default, [Default]no Action (7) Example Outtable table primary key ID type int To create a table that contains a foreign key: Copy CodeThe code is as follow
In MySQL, a table with the InnoDB engine type supports foreign key constraints.Use conditions for foreign keys:1. Two tables must be INNODB tables, MyISAM table temporarily does not support foreign keys (it is said that future versions may be supported, but at least not curr
MySQL Learning (4) -- foreign key, mysql learning foreign key
1. For example, there are two tables: "Classification Table" and "commodity table". To indicate the category of a commodit
Mysql foreign key
BitsCN.com
In MySQL, tables of the InnoDB engine type support foreign key constraints.Usage conditions of foreign keys:1. the two tables must be InnoDB tables, and M
ACTION | SET DEFAULT}]This syntax can be used when creating table and ALTER table, and if you do not specify constraint Symbol,mysql automatically generates a name. On DELETE, the on update indicates the event-triggering limit, and can be set with parameters:RESTRICT (Restrict foreign key changes in appearance)CASCADE (following
] (index_col_name, ...)REFERENCES tbl_name (index_col_name, ...)[on DELETE {RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT}][on UPDATE {RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT}]This syntax can be used when creating table and ALTER table, and if you do not specify constraint Symbol,mysql automatically generates a name.On DELETE, the on update indicates the event-triggering limit, and can be set with parameters:RESTRICT (Restric
In MySQL, tables of the InnoDB Engine type support foreign key constraints.Usage conditions of foreign keys:1. The two tables must be InnoDB tables, and MyISAM tables do not currently support foreign keys (it is said that foreign
storage engine must be InnoDB, otherwise create a foreign key without a constraint effect.2. The column type of the foreign key must be exactly the same as the primary key type of the parent table.3. The name of the foreign
operations cannot be nested for more than 15 layers.
Deviations from SQL standards: Similar to MySQL, InnoDB checks UNIQUE and foreign key constraints row by row in an SQL statement that inserts, deletes, or updates many rows. According to the SQL standard, the default behavior should be checked for delay, that is, the constraint is checked only after the entire
corresponding field of the child table is empty after the parent table operation4, the use of foreign key premise:1. The table storage engine must be InnoDB, otherwise create a foreign key without a constraint effect.2. The column type of the foreign
reference A.AFK, the value inserted by B.BFK must be an existing in A.AFK 4, the simple point of 3 is that if B has a as a reference to the foreign key, then the value of this field in B can only be a value in a, from table B will be in real time by the main Table a constraints, and if the associated with the delete on update and other operations when the referenced field in a delete or update , the corres
When a foreign key is added to MySQL, the following error occurs: 1215 Cannot add the foreign key constraint, 1215 constraint
Preface
This article mainly covers ERROR 1215 (HY000): Cannot add foreign
ACTION | SET DEFAULT}][on UPDATE {RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT}]This syntax can be used when creating table and ALTER table, and if you do not specify constraint Symbol,mysql automatically generates a name.On DELETE, the on update indicates the event-triggering limit, and can be set with parameters:RESTRICT (Restrict foreign key change
Each of the two fields that are foreign keys must be primary keys Two tables must be a InnoDB table,MyISAM table temporarily does not support foreign keysThe columns of the two tables of the foreign key relationship must be of similar data types, that is, columns that can be converted to each other, such as int and t
constrained by the model field of the Parts table.
In this way, our foreign key is OK. If we try to create a PC, it uses a CPU model that does not exist in the parts table, then MySQL will prohibit the PC from being created.
Cascade Operations
Consider the following:
Technicians found that the models of a series of CPUs that were entered into the parts table
This article mainly introduces the difference and connection between the primary key and the foreign key in MySQL. it is the basic knowledge in MySQL beginners. if you need it, you can refer to the relationship between the primary key
delete and on update. You can set the parameters cascade (with foreign key changes), restrict (with foreign key changes in the external table), and set Null (with Null values ), set Default (set Default value), [Default] no action
(7) Example
OutTable table primary
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.