Last answered:

24 Aug 2022

Posted on:

28 Oct 2021

0

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?

6 answers ( 1 marked as helpful)
Posted on:

28 Oct 2021

1

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.

Instructor
Posted on:

06 Nov 2021

1

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

Posted on:

30 Jun 2022

0

As you said _ibfk_1 unless we provide a name but how we assign a name to a foreign key in SQL statement

Instructor
Posted on:

01 Jul 2022

1

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

Posted on:

23 Aug 2022

0

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?

Instructor
Posted on:

24 Aug 2022

1

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

Submit an answer