sql - MySQL: does it matter to give names to the foreign keys? -


tell me please either should give name foreign key?

constraint constraint_name foreign key foreign_key_name (columns) references parent_table(columns) on delete action on update action 

i can manipulations constraint it's name, can foreign key name? give me examples please.

as documentation explains:

mysql requires indexes on foreign keys , referenced keys foreign key checks can fast , not require table scan. in referencing table, there must index foreign key columns listed first columns in same order. such index created on referencing table automatically if not exist. index might silently dropped later, if create index can used enforce foreign key constraint. index_name, if given, used described previously.

in other words, providing not "foreign key name" "(foreign key) index name".

having name index useful tracking index.

to honest, though, don't provide such names. rather explicitly declare index on foreign keys, rather have database me.

(note: databases not automatically create index when foreign key declared.)


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -