MySQL foreign key after the set, if we no longer need this foreign key, can be deleted, the following will introduce you to the MySQL delete foreign key definition method, for your reference.
Do not know whether we have found that the foreign key in the definition of the foreign key articles.member_id than the ARTICLES.CATEGORY_ID clause more than a constraint fk_member?
This fk_member is used to implement the MySQL delete foreign key, as follows:
- MySQL> ALTER TABLE articles DROP FOREIGN KEY fk_member;
- Query OK, 1 row affected (0.25 sec)
- Records:1 duplicates:0 warnings:0
This articles.member_id the foreign key definition is deleted, but if the definition does not specify constraint Fk_symbol (that is, the foreign key symbol) when the implementation of the MySQL delete foreign key? Don't worry, MySQL will create one yourself when not specified, and can be viewed with the following commands:
- MySQL> SHOW CREATE TABLE articles;
- + ———-+ ———————————— +
- | Table | Create Table |
- + ———-+ ———————————— +
- | Articles | CREATE TABLE ' articles ' (
- ' article_id ' int (one) unsigned not NULL auto_increment,
- ' category_id ' tinyint (3) unsigned not NULL,
- ' member_id ' int (one) unsigned not NULL,
- ' title ' varchar (255) Not NULL,
- PRIMARY KEY (' article_id '),
- KEY ' category_id ' (' category_id '),
- KEY ' member_id ' (' member_id '),
- CONSTRAINT ' Articles_ibfk_1 ' FOREIGN KEY (' category_id ') REFERENCES ' categories ' (' ID ')
- ) engine=InnoDB DEFAULT charset=latin1 |
- + ———-+ ———————————— +
- 1 row in Set (0.01 sec)
You can see that the articles.category_id foreign key symbol is articles_ibfk_1, because you can execute the following command to implement the MySQL delete foreign key definition:
- MySQL> ALTER TABLE articles DROP FOREIGN KEY articles_ibfk_1;
- Query OK, 1 row affected (0.66 sec)
- Records:1 duplicates:0 warnings:0
MySQL Delete method of foreign key definition