Difference between Constraint and `index_name` characters for foreign keys

The MySQL syntax for adding a foreign key in an Alter Table command is as follows:

ADD [CONSTRAINT [symbol]] FOREIGN KEY [index_name] (index_col_name,...) 

What is the difference between CONSTRAINT symbol and index_name . From what I can make out, they are both ways of naming a foreign key, but I suppose there should be more differences, can someone enlighten me?

+4
source share
1 answer

[character] - this is the name of the constraint, if it is specified, MySQL will create a foreign key and index with the name [character] ; in this case, [index_name] is ignored.

The second [index_name] is the name of the index. This index is created automatically. If the [character] parameter is omitted, the foreign key will be called the server, and the index will be called [index_name] .

+4
source

Source: https://habr.com/ru/post/1444067/


All Articles