All right.
So let me go ahead and show how to delete a foreign key in PostgreSQL.
First of all, let's go ahead and look at our tables again.
So I have this table.
And I see this is a the first of all select all from stress level.
So select all from students and puts semicolon end.
And this is our students table underscore head and down select.
All from foreign which is semicolon end.
And this is what we have.
No the foreign key which we created is a foreign key constraint for the students which references the
table.
Uh form.
Let's go ahead and go back here.
And I'm going to say students.
And uh now you can see that the stiletto has a foreign key constraint named as trace underscore for
id underscore f key.
Why we haven't said f d d and change the font table.
And now this references the students table because the foreign key is actually a constraint in the students
table.
We can see that table student constraint.
Still only the underscore f key foreign key foreign ID references the foreign table which has a permanent
key ID where it references.
Now I can actually go ahead and delete anything from the strange table.
What?
I can delete any D which is assigned to any of the student.
Let's go ahead and see.
I can actually delete uh, Steve and Steve has a this ID three assigned to it.
I can comfortably delete your Steve without affecting the full table was.
I cannot go ahead and delete this Samsung without first deleting Judge Steve.
Let's go ahead and give you an example so it can be able to see what is actually going on here.
So if I go ahead and see uh when I say delete.
So um deletes from from and where.
ID is equal to three and put a semicolon in and hit enter unknown.
You can see we have an error.
It says update or delete on telephone violates foreign key constraints.
Student's phone ID uh f key on table students.
So details key ID equals to three is two the first from table students.
What I can confidently go ahead and delete uh, this table or this row called George which references
that table.
Now let's go ahead and see onto delete.
Go ahead and delete the wrong students.
And the one I'm going to delete is, uh, I'm going to delete from strings where the students where
the students underscore ID is equal to.
This idea of joy and idea of joy is one that is just so where the stress is equal to one.
I put a silicone in and let's go ahead and hit enter.
And down here you can see I have delete one.
So let's go ahead and just select all from.
While I select all from today's table I'll put a semicolon and then hit enter.
And now you can see I hadn't left it a wasteland uh, and took away because we have deleted that.
And the casino definitely is no longer there when you go ahead and select all.
From the Thredbo from file and put all.
For a phone, call it in and hit enter.
You can see we see how some songs are in here.
Now I can comfortably go ahead and delete this.
Some songs.
Let's go ahead and check it out.
So delete one.
So let it phone phone where the ID be equal to three.
And now the score hit and out with a semicolon at the end and hit enter.
And you can see we have delete.
Now let's go ahead and send it over to a phone.
Go ahead and select all from phone up to the end and hit enter.
And you can see that some song has been deleted.
So in this way you can actually, uh, learn how to delete a foreign key.
And you have to also, first of all, delete that, uh, Our table or delete doodle, which reverses
the order table.
And here we have the student table, because we can be able to delete the, uh, any row for the for
the row when it refreshes, or it has a reference from the students table.
So whenever you assign anything to another table, you first have to delete that foreign key before
it can be able to delete the reference table.
So I hope that is cool.
So this is about delete is very important to learn it because you might score head to delete this and
then be like wow, what is going on and how can I be able to delete that?
And you might be like, wow, what is really going on?
How can I be able to do this?
So now we have learned how to do it.
Go ahead and check it out, practice with it and if you have any question or had I used the question
and answer section and I'm going to get back to you as soon as possible.
Thank you so much.
And I'm going to see you in the next video lecture.