WEBVTT

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

00:07.850 --> 00:14.720
So let's go ahead and assign phones to our students is in the foreign key constraint which we created

00:14.720 --> 00:16.280
in the previous lecture.

00:16.370 --> 00:19.130
Now let's go ahead and see at tables.

00:19.130 --> 00:26.840
So select uh oh from students.

00:26.840 --> 00:32.810
And then this you can see that uh each of these students, none of them have a phone assigned to them.

00:32.810 --> 00:36.590
So only the phone ID, it is actually nothing there.

00:36.590 --> 00:47.030
And then let's go ahead and see the phone on this guy and say select uh oh from phone and put a semicolon

00:47.030 --> 00:47.540
at the end.

00:47.540 --> 00:49.010
And let's go ahead and check it out.

00:49.070 --> 00:54.320
Now we have to know how I made and Samsung and want to assign one of these.

00:54.350 --> 00:55.250
Let's go ahead and see.

00:55.250 --> 00:58.400
I'm going to assign some song to George Steve.

00:58.400 --> 01:04.120
And if I want to do that how can I be able to do that using the foreign keys.

01:04.480 --> 01:13.090
If I want to assign a form to Steve, or I need to do is to go ahead and say update, and I'm going

01:13.090 --> 01:16.120
to update the students table.

01:16.120 --> 01:26.770
So update students and I'll go ahead and set this form, the form table, which is here.

01:26.770 --> 01:35.950
And go ahead and say set a form underscore ID uh equal to.

01:35.980 --> 01:37.570
I'll go ahead and select three.

01:37.600 --> 01:43.510
If I select three that means I want to assign the ID three which is Samsung, to Steve.

01:43.510 --> 01:44.830
And that is three.

01:44.830 --> 01:49.120
And then I'm going to assign that via this ID is equal to one.

01:49.120 --> 01:53.440
So go ahead and say assign that where id is equal to one.

01:53.440 --> 01:58.360
And put a semicolon and the id where id which is stress ID.

01:58.720 --> 02:00.190
Go ahead and delete this.

02:00.190 --> 02:06.090
We are Students underscore ID is equal to one.

02:06.390 --> 02:06.750
All right.

02:06.780 --> 02:11.370
So if you go ahead and hit enter we can see we have update.

02:11.370 --> 02:18.510
And let's go ahead and uh select oh from.

02:22.740 --> 02:23.250
Students.

02:23.250 --> 02:25.350
And put a semicolon at the end and hit enter.

02:25.350 --> 02:33.960
And right now you can see that Steve has uh some song which is ID uh, font ID three assigned to it.

02:33.990 --> 02:36.990
So you can see that we have assigned this to Judge Steve.

02:36.990 --> 02:45.330
And if I want to assign Motora to maybe to Toby or Lulu, I'll go ahead and say, okay, we're going

02:45.330 --> 02:49.380
to assign this to Lulu, and I'm going to assign it to Lulu.

02:49.380 --> 02:55.320
And then what I need to do is that, uh, the ID of row is two added ID the font ID is one.

02:55.320 --> 02:59.220
So I'll go ahead and say update.

03:01.340 --> 03:04.880
The streets.

03:04.910 --> 03:05.900
The table.

03:05.930 --> 03:14.750
Then go ahead and set the phone underscore ID equal to that is your phone underscore ID is one for Motorola.

03:14.750 --> 03:20.960
And uh go ahead and see where the stress ID.

03:24.020 --> 03:30.530
Where the students underscore ID is equal to that is zero is equal to three.

03:30.530 --> 03:36.980
So when I say stress underscore ID is equal to three, I'll put a semicolon at the end and hit enter.

03:36.980 --> 03:38.630
And we have this updated.

03:38.660 --> 03:45.830
Now if I go ahead and uh select oh from.

03:47.900 --> 03:48.410
Stress.

03:48.410 --> 03:50.840
And put a semicolon at the end and hit enter.

03:50.840 --> 03:59.300
You can see that uh, George has some song which is uh, the ID three for Samsung assigned to it while

03:59.330 --> 04:08.960
rural has, uh, this, which is, a muttaburra and that is the ID one assigned to it.

04:08.960 --> 04:11.690
So we have to stress assign phones.

04:11.720 --> 04:22.790
Now let me go ahead and see that maybe we want to assign this some song and some song is ID three.

04:22.820 --> 04:24.470
I'll go ahead and drag this down a little bit.

04:24.500 --> 04:25.820
Samsung is ID three.

04:25.820 --> 04:32.240
And once I assign that to maybe topi and topi which has not anything assigned to it.

04:32.270 --> 04:34.790
If we go ahead and do that, let's see what is going to happen.

04:34.820 --> 04:35.840
Go ahead and say.

04:38.210 --> 04:39.170
Updates.

04:41.540 --> 04:42.320
Strains.

04:43.250 --> 04:50.810
Uh, table and dashboard and uh, sets phone underscore ID equal to.

04:50.840 --> 05:03.040
And that is three for the Samsung where the students underscore ID is equal quote tool.

05:03.160 --> 05:06.040
Let me say maybe it's for 2 or 3 for two.

05:06.310 --> 05:09.490
That is the flow.

05:09.520 --> 05:11.920
And put the semicolon at the end and hit enter.

05:11.920 --> 05:16.990
And now you can see we have a duplicate key value versus the unique constraint.

05:16.990 --> 05:20.470
Because we make that issue so that we have a phone assigned to them.

05:20.470 --> 05:25.330
So if we want to do that we have to go ahead and insert a new phone right in here.

05:25.360 --> 05:30.010
Or we go ahead and insert email because no two students will have the same phone.

05:30.040 --> 05:30.700
All right.

05:30.730 --> 05:33.940
That is it because the IDs are separate.

05:33.940 --> 05:38.650
So you're not going to send ID, which I've assigned to a student to another student.

05:38.680 --> 05:45.610
But if I go ahead and copy everything right in here and go ahead and paste it here, and I change the

05:45.640 --> 05:48.400
ID of the phone and we have one of them remaining.

05:48.400 --> 05:54.250
And that is two for I met and I changed it up to two and put a semicolon and hit enter.

05:54.280 --> 05:59.200
And uh let's see okay.

05:59.200 --> 06:03.360
So we have this where the stress ID is equal to two.

06:03.390 --> 06:05.940
So we're talking about the font we have assigned the font.

06:05.970 --> 06:13.080
When I press this and I'll go right in here and change the font ID to white and change this font ID

06:13.410 --> 06:14.820
to two.

06:15.720 --> 06:16.320
All right.

06:16.320 --> 06:21.450
And now let's go ahead and uh hit enter and see what happens.

06:21.480 --> 06:23.130
Now I have updated that.

06:23.130 --> 06:33.270
So go back and uh select uh oh from students and put a semicolon at the end and hit enter.

06:33.270 --> 06:36.300
And now you can see that Toby has.

06:36.300 --> 06:38.850
Now I made a sign to him.

06:39.060 --> 06:43.980
So now two strings are going to have the same phone, uh, with font ID assigned to them.

06:43.980 --> 06:46.530
And that is the part of foreign keys.

06:46.530 --> 06:52.710
So we are referencing the two tables, and you can see that you cannot assign a foreign which you are

06:52.710 --> 06:56.010
assigned to a students already to another student.

06:56.040 --> 06:56.700
All right.

06:56.700 --> 07:05.570
And uh, let's go ahead and say maybe backward slash DC to see everything and to have these two tables

07:05.570 --> 07:06.290
right in here.

07:06.290 --> 07:09.530
And these two tables are actually communicating.

07:10.310 --> 07:15.650
So if you go ahead and let me go ahead and say, I want to view this table, because that is where the

07:15.650 --> 07:22.700
foreign key is actually is going in and say, uh, backward slash D and then go ahead and view students

07:22.700 --> 07:23.720
and hit enter.

07:23.750 --> 07:26.210
Now you can see we have foreign key constraint.

07:26.210 --> 07:31.640
And that is trans underscore foreign aid underscore f uh t.

07:31.700 --> 07:34.550
And that is the foreign L.

07:34.580 --> 07:37.010
The phone ID cannot be assigned to two persons.

07:37.010 --> 07:40.040
And you can see that is the foreign key references.

07:40.040 --> 07:44.660
So every students need to have a unique phone ID assigned to them.

07:44.660 --> 07:46.190
So I hope that is cool.

07:46.280 --> 07:47.360
Go ahead and put this down.

07:47.390 --> 07:48.080
Foreign rotate.

07:48.080 --> 07:51.380
And if you have any question go ahead and use the question and answer section.

07:51.380 --> 07:53.780
And I'm going to get back to you as soon as possible.

07:53.810 --> 07:54.710
Thank you so much.

07:54.710 --> 07:57.680
And I'm going to see you in the next video lecture.
