All right.
So let's go ahead and assign phones to our students is in the foreign key constraint which we created
in the previous lecture.
Now let's go ahead and see at tables.
So select uh oh from students.
And then this you can see that uh each of these students, none of them have a phone assigned to them.
So only the phone ID, it is actually nothing there.
And then let's go ahead and see the phone on this guy and say select uh oh from phone and put a semicolon
at the end.
And let's go ahead and check it out.
Now we have to know how I made and Samsung and want to assign one of these.
Let's go ahead and see.
I'm going to assign some song to George Steve.
And if I want to do that how can I be able to do that using the foreign keys.
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
to update the students table.
So update students and I'll go ahead and set this form, the form table, which is here.
And go ahead and say set a form underscore ID uh equal to.
I'll go ahead and select three.
If I select three that means I want to assign the ID three which is Samsung, to Steve.
And that is three.
And then I'm going to assign that via this ID is equal to one.
So go ahead and say assign that where id is equal to one.
And put a semicolon and the id where id which is stress ID.
Go ahead and delete this.
We are Students underscore ID is equal to one.
All right.
So if you go ahead and hit enter we can see we have update.
And let's go ahead and uh select oh from.
Students.
And put a semicolon at the end and hit enter.
And right now you can see that Steve has uh some song which is ID uh, font ID three assigned to it.
So you can see that we have assigned this to Judge Steve.
And if I want to assign Motora to maybe to Toby or Lulu, I'll go ahead and say, okay, we're going
to assign this to Lulu, and I'm going to assign it to Lulu.
And then what I need to do is that, uh, the ID of row is two added ID the font ID is one.
So I'll go ahead and say update.
The streets.
The table.
Then go ahead and set the phone underscore ID equal to that is your phone underscore ID is one for Motorola.
And uh go ahead and see where the stress ID.
Where the students underscore ID is equal to that is zero is equal to three.
So when I say stress underscore ID is equal to three, I'll put a semicolon at the end and hit enter.
And we have this updated.
Now if I go ahead and uh select oh from.
Stress.
And put a semicolon at the end and hit enter.
You can see that uh, George has some song which is uh, the ID three for Samsung assigned to it while
rural has, uh, this, which is, a muttaburra and that is the ID one assigned to it.
So we have to stress assign phones.
Now let me go ahead and see that maybe we want to assign this some song and some song is ID three.
I'll go ahead and drag this down a little bit.
Samsung is ID three.
And once I assign that to maybe topi and topi which has not anything assigned to it.
If we go ahead and do that, let's see what is going to happen.
Go ahead and say.
Updates.
Strains.
Uh, table and dashboard and uh, sets phone underscore ID equal to.
And that is three for the Samsung where the students underscore ID is equal quote tool.
Let me say maybe it's for 2 or 3 for two.
That is the flow.
And put the semicolon at the end and hit enter.
And now you can see we have a duplicate key value versus the unique constraint.
Because we make that issue so that we have a phone assigned to them.
So if we want to do that we have to go ahead and insert a new phone right in here.
Or we go ahead and insert email because no two students will have the same phone.
All right.
That is it because the IDs are separate.
So you're not going to send ID, which I've assigned to a student to another student.
But if I go ahead and copy everything right in here and go ahead and paste it here, and I change the
ID of the phone and we have one of them remaining.
And that is two for I met and I changed it up to two and put a semicolon and hit enter.
And uh let's see okay.
So we have this where the stress ID is equal to two.
So we're talking about the font we have assigned the font.
When I press this and I'll go right in here and change the font ID to white and change this font ID
to two.
All right.
And now let's go ahead and uh hit enter and see what happens.
Now I have updated that.
So go back and uh select uh oh from students and put a semicolon at the end and hit enter.
And now you can see that Toby has.
Now I made a sign to him.
So now two strings are going to have the same phone, uh, with font ID assigned to them.
And that is the part of foreign keys.
So we are referencing the two tables, and you can see that you cannot assign a foreign which you are
assigned to a students already to another student.
All right.
And uh, let's go ahead and say maybe backward slash DC to see everything and to have these two tables
right in here.
And these two tables are actually communicating.
So if you go ahead and let me go ahead and say, I want to view this table, because that is where the
foreign key is actually is going in and say, uh, backward slash D and then go ahead and view students
and hit enter.
Now you can see we have foreign key constraint.
And that is trans underscore foreign aid underscore f uh t.
And that is the foreign L.
The phone ID cannot be assigned to two persons.
And you can see that is the foreign key references.
So every students need to have a unique phone ID assigned to them.
So I hope that is cool.
Go ahead and put this down.
Foreign rotate.
And if you have any question go ahead and use 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.