WEBVTT

00:07.370 --> 00:07.850
All right.

00:07.850 --> 00:12.470
So let me go ahead and show how to delete a foreign key in PostgreSQL.

00:13.130 --> 00:15.860
First of all, let's go ahead and look at our tables again.

00:15.860 --> 00:17.390
So I have this table.

00:17.780 --> 00:23.870
And I see this is a the first of all select all from stress level.

00:24.140 --> 00:32.720
So select all from students and puts semicolon end.

00:32.720 --> 00:36.350
And this is our students table underscore head and down select.

00:39.380 --> 00:44.360
All from foreign which is semicolon end.

00:44.360 --> 00:45.680
And this is what we have.

00:45.860 --> 00:54.290
No the foreign key which we created is a foreign key constraint for the students which references the

00:54.290 --> 00:55.040
table.

00:55.280 --> 00:56.390
Uh form.

00:56.660 --> 00:58.550
Let's go ahead and go back here.

00:58.550 --> 01:01.370
And I'm going to say students.

01:01.370 --> 01:08.270
And uh now you can see that the stiletto has a foreign key constraint named as trace underscore for

01:08.300 --> 01:10.160
id underscore f key.

01:10.190 --> 01:16.910
Why we haven't said f d d and change the font table.

01:16.910 --> 01:26.360
And now this references the students table because the foreign key is actually a constraint in the students

01:26.360 --> 01:26.840
table.

01:26.870 --> 01:29.450
We can see that table student constraint.

01:29.480 --> 01:38.150
Still only the underscore f key foreign key foreign ID references the foreign table which has a permanent

01:38.150 --> 01:40.730
key ID where it references.

01:40.760 --> 01:44.750
Now I can actually go ahead and delete anything from the strange table.

01:44.780 --> 01:45.200
What?

01:45.200 --> 01:50.180
I can delete any D which is assigned to any of the student.

01:50.210 --> 01:51.110
Let's go ahead and see.

01:51.140 --> 01:58.970
I can actually delete uh, Steve and Steve has a this ID three assigned to it.

01:59.060 --> 02:05.420
I can comfortably delete your Steve without affecting the full table was.

02:05.420 --> 02:11.240
I cannot go ahead and delete this Samsung without first deleting Judge Steve.

02:11.480 --> 02:15.710
Let's go ahead and give you an example so it can be able to see what is actually going on here.

02:15.710 --> 02:20.150
So if I go ahead and see uh when I say delete.

02:23.060 --> 02:29.510
So um deletes from from and where.

02:31.790 --> 02:37.730
ID is equal to three and put a semicolon in and hit enter unknown.

02:37.730 --> 02:39.260
You can see we have an error.

02:39.260 --> 02:44.300
It says update or delete on telephone violates foreign key constraints.

02:44.330 --> 02:49.250
Student's phone ID uh f key on table students.

02:49.430 --> 02:55.040
So details key ID equals to three is two the first from table students.

02:55.070 --> 03:01.340
What I can confidently go ahead and delete uh, this table or this row called George which references

03:01.340 --> 03:02.120
that table.

03:02.390 --> 03:05.760
Now let's go ahead and see onto delete.

03:05.790 --> 03:10.290
Go ahead and delete the wrong students.

03:10.290 --> 03:25.290
And the one I'm going to delete is, uh, I'm going to delete from strings where the students where

03:25.290 --> 03:29.220
the students underscore ID is equal to.

03:29.970 --> 03:36.600
This idea of joy and idea of joy is one that is just so where the stress is equal to one.

03:36.630 --> 03:39.660
I put a silicone in and let's go ahead and hit enter.

03:39.660 --> 03:43.560
And down here you can see I have delete one.

03:43.560 --> 03:47.760
So let's go ahead and just select all from.

03:49.590 --> 03:56.430
While I select all from today's table I'll put a semicolon and then hit enter.

03:56.430 --> 04:04.080
And now you can see I hadn't left it a wasteland uh, and took away because we have deleted that.

04:04.080 --> 04:09.150
And the casino definitely is no longer there when you go ahead and select all.

04:11.880 --> 04:17.220
From the Thredbo from file and put all.

04:19.860 --> 04:22.380
For a phone, call it in and hit enter.

04:22.410 --> 04:25.080
You can see we see how some songs are in here.

04:25.140 --> 04:27.420
Now I can comfortably go ahead and delete this.

04:27.420 --> 04:28.080
Some songs.

04:28.110 --> 04:30.150
Let's go ahead and check it out.

04:30.150 --> 04:32.160
So delete one.

04:32.160 --> 04:39.930
So let it phone phone where the ID be equal to three.

04:39.960 --> 04:43.860
And now the score hit and out with a semicolon at the end and hit enter.

04:43.860 --> 04:45.960
And you can see we have delete.

04:45.990 --> 04:49.920
Now let's go ahead and send it over to a phone.

04:49.950 --> 04:55.860
Go ahead and select all from phone up to the end and hit enter.

04:55.860 --> 04:58.560
And you can see that some song has been deleted.

04:58.770 --> 05:04.080
So in this way you can actually, uh, learn how to delete a foreign key.

05:04.110 --> 05:11.220
And you have to also, first of all, delete that, uh, Our table or delete doodle, which reverses

05:11.250 --> 05:12.300
the order table.

05:12.300 --> 05:21.060
And here we have the student table, because we can be able to delete the, uh, any row for the for

05:21.060 --> 05:26.280
the row when it refreshes, or it has a reference from the students table.

05:26.280 --> 05:32.250
So whenever you assign anything to another table, you first have to delete that foreign key before

05:32.250 --> 05:34.500
it can be able to delete the reference table.

05:34.500 --> 05:35.730
So I hope that is cool.

05:35.730 --> 05:41.460
So this is about delete is very important to learn it because you might score head to delete this and

05:41.460 --> 05:45.300
then be like wow, what is going on and how can I be able to delete that?

05:45.300 --> 05:48.150
And you might be like, wow, what is really going on?

05:48.150 --> 05:49.650
How can I be able to do this?

05:49.650 --> 05:51.420
So now we have learned how to do it.

05:51.420 --> 05:55.710
Go ahead and check it out, practice with it and if you have any question or had I used the question

05:55.710 --> 05:59.100
and answer section and I'm going to get back to you as soon as possible.

05:59.130 --> 06:00.000
Thank you so much.

06:00.000 --> 06:03.270
And I'm going to see you in the next video lecture.
