Resolved: DROP FOREIGN KEY sales_ibfk_1 -- huh?
Why does the video say DROP FOREIGN KEY sales_ibfk_1
instead of DROP FOREIGN KEY customer_id?
I figured out the answer. Type the command SHOW CREATE TABLE sales;
Then you will see the name of the constraint. Use that name instead of the column name:
ALTER TABLE sales
DROP FOREIGN KEY sales_ibfk_1;
I am using the online Goom.IDE instead of the Oracle SQL workbench and all that install//set-up stuff.
So my IDE doesn't have the tabs to show foreign keys.
Hi Michele!
Thanks for reaching out.
_ibfk_1, _ibfk_2 etc. are suffixes that Workbench automatically assigns to foreign keys unless we specifically provide a name to the given foreign key.
Other than that, thank you very much for sharing a solution to the given question!
Hope this helps.
Best,
Martin
As you said _ibfk_1 unless we provide a name but how we assign a name to a foreign key in SQL statement
Hi Mayank!!
Thanks for reaching out.
You can use the following code:
ALTER TABLE table_name
DROP FOREIGN KEY `_ibfk_1`,
ADD CONSTRAINT `name_FK` FOREIGN KEY (`column_name`) REFERENCES `table_name` (`column_name`)
Hope this helps.
Best,
Tsvetelin
Hello Tsvetelin, Mayank,
What an interesting question from Mayank.
Does that mean that the new foreign key you added will be named "name_FK"? Can we just name the foreign key with a similar name as the column name or there is a common practice in assigning names?
Hi Carl!
Thanks for reaching out.
This is an example name. The name should describe the column as you said. Also, the name of the foreign key is very similar or sometimes the same as the primary key.
Hope this helps.
Best,
Tsvetelin