I will call you back again to another video lecture on MySQL.
And in this lecture I'll go ahead and teach you how to update data and also delete a data in MySQL.
All right.
Let me go ahead and say if you followed me from the beginning of this course and you installed MySQL
newly, say let me say you're a beginner in MySQL.
You don't have any knowledge of this before and you really install this workbench with me.
First of all, move over to edit and click on edit and move to preferences.
Now we get to preferences.
Go ahead and click on SQL editor.
Now if you click on this, just the SQL editor.
Then drag this down.
Over here you can see safe updates, rejects, updates and deletes with that with no restrictions.
So if you install this newly, you're going to see that this is ticked means that you cannot be able
to update or delete anything because it's in safe mode, so go ahead and deselect it.
To remove this and then go ahead and click on okay.
And when you click okay you go ahead and restart your workbench.
Close the workbench and restart.
Because if you try to actually update any data in our database, nothing will happen.
So when you deselect that, you go ahead and restart your workbench and then you come back to this lecture.
Now I'll go ahead and teach you how to update a data in your table.
So to update.
Go ahead and use the update keyword.
And we go ahead and specify say students because we're using the students table.
And go ahead and say set.
So after set whatever we want to update.
Now under the table I have Judge Steve and Judge table has no GP and it has no enrollment date.
So we need to give it a GP.
I also need to add the enrollment dates here.
So what I'm going to say is I want to set the GPA first, then I'll show you how to do both at the same
time.
So say the GPA and let GPB go to 4.1.
And there we go ahead and say if we're going to set this for Judge Steve, we're going to tell if we
are doing this based on the first name or last name or status ID.
So there's got to be a class showing the row you are working with.
So if you are working with row eight you're going to set this to be stress ID equal to row eight.
Or we are strength name or we are first name is equal to George or we are last name is equal to Steve.
So we're going to give it a real class.
So go ahead and see where.
Then I'm going to use the stress ID.
So it's going to be okay.
So we are stress ID is equal to eight.
So over here you can see that George Steve is equal to eight.
Then go ahead and put a semicolon at the end.
Then we're to populate this as well.
So it can be able to see that.
So select all From students, so I had to place a semicolon at the end.
Then go ahead and execute this query and check it out.
So we have one school, uh, it says unknown column A student ID.
So this is students ID and not student ID.
If you go back to that table what we have is a student's ID.
So go ahead and execute this query again.
And we have this here.
Now you can see that Steve is 4.1.
All right.
So we have given a GP right in here.
And that is cool.
Now if we want to add enrollment dates so you can do both of them at the same time.
No problem.
Go ahead and put a set GP equal to 4.1 comma.
And then go ahead and specify these.
Uh let me say in row underscore date.
All right.
So you can actually go ahead and do this in one line.
Right.
So I'm just making these two guidelines say a row underscore dates and uh, late dates be equal to.
Then go ahead.
I say this is a 2099 and the amount is 12 and the day is nine.
So if you can specify this, you can go ahead and execute this query and check it out.
And here we have Steve now has a GPA of 4.1 and in row on 2099 12 zero nine.
So you can see that that is cool.
Go ahead and drag this up a little bit.
I want everything to be showing and this is what we have.
So in this way can we move to actually update.
And then you can also be able to do that individually.
Okay I hope that is cool.
So now let me say what we are cross affects all the columns.
Let me go ahead and say I don't just want to update only to Steve to be a GPA of 4.1.
I want every GPA right in here to be equal to 4.1.
How can you be able to do that?
So this is going to affect everything we have here okay.
If we're able to do that, okay.
It's going to affect everything we have here.
So we're going to change everything from a let me say what will this change.
Everything.
So let me go ahead and say.
Remove this.
And uh go ahead and also remove this.
And then going to say update students set equal to 4.1.
And go ahead and execute this query.
And you can see we have actually changed everything to 4.1.
Wow.
So you can also go back and do this individually.
Just put them back the way they are right.
So we have been able to see how it goes.
Now if I want I can actually update students and I'm going to set the date to like, no, we want to
set everything to no.
Right.
So remember when I put this back again and uh, I have students ID equal to eight, so I can actually
go ahead and say this is equal to null.
Right.
So and if I go ahead and do this query we go back.
We can see we've removed the enrolled dates for Steve.
And that is no.
So in this way you can actually update your students.
You can do that individually.
And uh everything is going to work out fine.
So you can see you can select a full a complete column and that you can alter the complete column.
You can do that individually.
You can do that for a whole table.
So I hope that is cool.
Now let me say I want to delete I want to delete some data.
If I go ahead and say delete and I go ahead and say delete from students.
Now I want to advise you to actually do this, because if you do this, it's going to delete every data
right in here.
And the way you do that, you have to go ahead and create a new data again.
And that just want to delete everything, I want to delete where and what reason.
We are close right now.
So I'm going to say that is from students.
Then I'm going to add via class.
Because if you don't add up class it's going to delete everything.
So we are students underscore ID is equal to its previous record.
And then we go ahead and hit on execute.
And now we don't have Judge Steve in our database again.
So we can see that Judge Steve is no longer there.
All right.
So that is a way you can actually update data on your tables.
You can also delete data from your table.
And that is so cool.
Go ahead and practice that.
Try out this and run with your database and see what awards you are doing right in there.
So that is cool.
So I'm going to say thank you so much.
And I'm going to see you in the next video lecture.
Number.