Dropping or updating uniq, foreign key in mysql tables

If you need to drop an index or uniq column from mysql, in the command line,

first find out the FK or UNIQ key,

“show create table table_name”;

now, you will see the sql for creating a table, copy and paste the key, eg

“drop index FK_40123345 on table_name;”

To double check if this is correct, run

“describe table_name”

If when updating tables, you get foreign key constraint error, you need to disable foreign key check first, then update the table. ie, in command line,

“set global foreign_key_checks=0”

after you run the sql updates, remember to turn the check back on

“set global foreign_key_checks=1”

Like it.? Share it:

Comments are closed.