Welcome back.
I've added one more user here so we have a little bit of a bigger database.
But let's say we have a problem.
We realized that we we're working on this project and oops we actually needed to also include a score
column.
How can we add another column to a pre-existing table.
We have SQL for that, we can use alter table. And using this format we can add a new column.
So let's say that in the users table we want to add a column that is score and data type, we want - let's
say smallint, a score that can be over 30,000.
So let's say Max score is a thousand so smallint will be fine.
I press enter and now we have altered table.
If I refresh here.
Go to users, I see that I have scores but we have a problem now.
We have scores but it's null.
There's nothing for these users.
What if we wanted to just update the information here to include the scores.
Let's try and do that.
To update we have the update table name and we have three rows which we don't want but for now I just
want to show you we have update table name.
And then we want to say set whichever column we want to equal a value, where the column equals some value.
That looks confusing doesn't it.
Let me show you what I mean.
I can say UPDATE users and in the users
I want to SET score column to equal what do we want it to equal.
Let's say that we want Andrei to have a score of 50.
We can say UPDATE users set score 50 WHERE which is another key word name
equals 'Andrei'. It reads pretty nicely right.
Update users set the score to 50 if the column name is Andrei.
Looks like we got an update.
If I now do select star from users, I see that I have Andrei with score 50.
And you know what we also want to update Sally and John. But they both have the same score of let's say
100.
How can we do that.
We can say UPDATE users SET score to
100 WHERE name equals John but also we can say AND name equals Sally. If i press enter I get an update.
If I go up to select users.
You see that I did not get an update and that is because
AND just like we did in javascript means that name should equal John and Sally.
And we don't have that.
It should be Sally or John.
Right.
So we can just press up to get our old command and change this to OR. We have 2 updates that just happened.
And if I look up users look at that.
I have Sally and John with score 100 and Andrei with 50. Looking at our GUI
if I refresh, look at that we have our table with our new scores.
Very cool.
A few more commands that I want to show you in the next video, so I'll see you on that one.
Bye-bye.