Stefan Edwards
Stefan Edwards

Reputation: 87

how to drop foreign key relation in the mysql table

I have one table X. I need to drop all the foreign keys in the table. I don't know how to drop. Can any one please say the query.

Upvotes: 2

Views: 21162

Answers (3)

Akshay Sharma
Akshay Sharma

Reputation: 1112

  1. Go to structure view of the table
  2. You will see 2 options at the top
    a. Table structure
    b. Relation view.
  3. Now click on Relation view , here you can drop your foreign key constraint.

Upvotes: 2

Joe G Joseph
Joe G Joseph

Reputation: 24046

probably, you should get the foreign keys using

SHOW CREATE TABLE <your_table>

then delete the foriegn keys one by one

ALTER TABLE <table_name> DROP FOREIGN KEY <key_name>;

Upvotes: 6

Sundar G
Sundar G

Reputation: 1069

Read this will help you http://bugs.mysql.com/bug.php?id=14347
http://www.w3schools.com/sql/sql_foreignkey.asp The foreign key constraint has to be dropped by constraint name and not the index name. The syntax is:

alter table test_table drop foreign key test_tableconstraint

Upvotes: 1

Related Questions