Restriction character against index of foreign key name & # 8594; who cares?

In mysql, foreign keys are defined as follows:

[CONSTRAINT [symbol]] FOREIGN KEY
    [index_name] (index_col_name, ...)
    REFERENCES tbl_name (index_col_name,...)
    [ON DELETE reference_option]
    [ON UPDATE reference_option]

Why do we need a CONSTRAINT and a symbol? There seems to be an index_name anyway, so I don't completely understand the reason for the CONSTRAINT keyword. Can someone clarify what this is for?

+4
source share
2 answers

CONSTRAINTis a keyword that tells MySQL that you want to add a constraint. [symbol]is an optional name for the restriction. You can name it whatever you want. If you omit this name, MySQL will generate the name on its own, internally.

It's good to use a prefix fklike fk_something.

If you cancel the restriction, you will need this symbol name:

ALTER TABLE tbl_name DROP FOREIGN KEY fk_something;

, SHOW CREATE TABLE:

SHOW CREATE TABLE tbl_name;

. , CONSTRAINT, (, , ).

MySQL.

+5

MySQL Ref

index_name . , , . , MySQL , index_name .

0

All Articles