Remove MySQL Foreign Key: Step-by-Step
To remove foreign key constraints in MySQL, you can use the ALTER TABLE statement with the DROP FOREIGN KEY clause. The specific steps are as follows:
- First, use the DESC command to query the table structure and find the name of the foreign key constraint.
DESC table_name;
- Next, delete the foreign key constraint using the ALTER TABLE statement and the DROP FOREIGN KEY clause.
ALTER TABLE table_name DROP FOREIGN KEY constraint_name;
Among them, table_name is the name of the table, and constraint_name is the name of the foreign key constraint.
After executing the SQL statement above, the foreign key constraint will be successfully removed.