I will call you back again to another lecture on MySQL.
And in this lecture we go ahead and learn how to create a table in a database.
Oh I saw over here on the database we created in the previous lecture.
You can see we have no tables because the table is too empty.
So if we refresh this there is no table read in here.
Now to create a table you go ahead and say create and say table.
Then you give the name of the table.
So you are free to choose any name based on something related to what you are doing.
So I have my school, so I want my table name to be students.
And then I'll go ahead and add in the details I need to collect from the students.
So I need to create ID because each of the students are going to have a unique ID.
And this ID is very, very important in database Creation.
So I'll go ahead and say it.
Studies underscore ID and the ID is going to be integer numbers or integer data types.
So it's going to be integer data types because you deal with the data types whenever you are creating
a table.
So that is an integer or is a decimal or is a character or dates and so on.
So for id id is always integer.
So it's going to be int and put a semicolon a comma.
So put a comma at the end.
And then I need the student's first name and last name.
So first underscore name.
Then this is a character.
So I'll go ahead and say it is varchar.
And now you give the number of characters you want might be 25.
And at the end and then I need the last name.
So it's also a character.
That is why the data type is going to be varchar.
So we comma at the end.
Then I'm going to collect that GPA.
So the GPA.
So go ahead and make it simple like GPA.
And the GPA is always a decimal.
It's going to be 4.13.52.0 and so on.
So I'm going to say this is decimal.
So now I'll go ahead and say this is one by one decimal place.
Okay.
So comma.
And then I'm going to give the enrollment date.
Let me say the enrollment date is going to be in raw underscore date.
And then this is a date.
So the data type is going to be date.
Oh no it's cool.
We have created a table.
And then I can go ahead and uh execute this query.
Go ahead and execute your query.
And uh down here you can see I have this query successfully.
Now if you go ahead and refresh that table, you can see we have a column where now No.
And there are.
This column contains these students ID first name, last name, GP and zero date.
All right.
Now you can write a query to the table.
Go ahead and go over here and remove this.
Go ahead and say Select and Auto select.
All because I want to populate every data we have right in there.
So in order to populate the column.
So go ahead and select all.
So the asterisk means auto select all.
So go ahead and select all from there students.
So that is the name of the table.
And if I go ahead and these days I have the column printed out student ID first name last name GP and
enroll date.
So hope that is cool.
All right that is very interesting.
Let's go ahead and write a query that we rename this to this table to something else.
And go ahead and say how to rename the student table to something else.
So I'm going to say Rename devil, and the devil I want to rename is, uh, students.
And I want to rename that to maybe like, purple.
All right.
There's a purpose for purple.
Anyone?
Now I'll go ahead and execute this query.
Let's check it out.
All right.
Now we have our students have changed this guy out of freshness.
And we have the table change to purple.
So you can see it has changed from students to pupils.
All right.
That is cool.
I will go ahead and put this back to let's go ahead and take Popus.
Go ahead and cut these and I'm going to replace that.
And I'm going to turn that to students because I'm going to maintain this to the end of this course.
Cut head and the kids and I'll refresh my table and I have my students table back and we have it here.
So that is cool.
Now what if we want to drop your table?
Go ahead and drop this table.
Go ahead and say I want to drop my table and say drop table.
Students.
I put a semicolon at the end.
Then if I hit on that, your table is gone.
You go ahead and create a table of fresh.
But I won't be dropping this table.
I wouldn't drop this table.
Here.
I'm going to leave that table the way it is, because I've learned how to drop a database.
And it can also the same way drop your table.
So I just want to show us so we can know what is going on.
Now I want to alter my table, which I just created.
And I want to add in maybe like a phone number of the students.
And all I need to do is I'll go ahead and say alter.
I want this to be an uppercase.
So let me go ahead and remove this and go and say alter.
And then I'll go ahead and say table.
Then give the name of the table students.
And then I want to add in.
Let me go ahead and say add phone underscore.
How can I say phone underscore.
No, that should be the phone number.
All right.
So instead of writing it to the end And this is going to be a varchar.
Okay.
All right.
So it can either be a varchar or it can be an integer.
You understand.
So it can actually use any one.
But I'm going to use varchar.
And I want to specify that this is like a 12 characters that I need and are semicolon at the end.
So all that is cool.
Now if you go ahead and execute this let's go ahead and see.
This is executed and got out a fresh piece.
And uh.
Over here I can see phone number.
Oh I hope that's cool.
And now if we go ahead and write another query to populate, this is going to say select uh all from
students.
And then with semicolon at the end then let's go ahead and select this.
We can see stress ID first name last name GP in row date and phone number.
Well, that is cool.
And, uh, you can actually go ahead and put this down for a run with it and try as much as possible
to add some things to that.
I can also change this column, maybe from phone number to email.
Yes, you can actually do that.
I can rename this from phone number.
I can rename that to be email.
What if I want to do that?
What I need to do is also let's say over to my table and I'm going to say statements.
And then I'll go ahead and uh rename that.
Let's go ahead and put this to the upper case.
Okay.
Causes a keyword.
So rename column.
Go ahead and say column.
Then when underscore number and I'm going to rename that to email.
Then put a semicolon at the end.
Then let's go ahead and populate that immediately.
So we can actually do the same thing if two at the same time.
So go ahead and say from and the students now I've got the kids and let's check it out so we can see
we have our stress ID, we have our first name.
We have the last name, we have the GPA, the enrolled date, and we have the email.
So I'm going to drag this a little bit down so it doesn't get up.
Now that is cool.
And I'm going to reduce this a little.
So it goes below.
All right.
That's cool I have to rename them back to email.
So I have renamed the phone number to email.
So go ahead and check it out.
And now if I refresh your table you can see it is now email and not phone number.
And you can actually change the size.
You can actually also change the size.
So let me drag this a little.
All right.
Now if we want to change the size of these is, uh.
Okay.
Let's go ahead and click on this.
And I want this to appear down here because he has synthesized down here.
And the email says it is our 12 characters.
What if I want to make this to be like 50 characters.
Well what I'm going to do or how am I going to alter that?
So if I want to alter that, what I need to do is, uh, I can actually go back here and I'm going to
change this to rename.
I'll get over to this point changes rename and I'm going to say modify.
So it is now modify.
And I'm going to say I'm modifying a column.
And that the column I want to modify is the email column.
And I want to give the Varchar.
And then the size is going to be 50 and no longer 12.
So the semicolon at the end.
And let's go ahead and skip this.
And down here we have it.
So you can see our guys are on a freshness.
And now I have a chore and it is 50 and no longer 12.
So in that way I've been able to modify that.
Now what if I want to move this email to call?
Maybe after the first name or last name or GP, then how can you be able to do that?
Let's say I have first name, last name, date.
Your email comes next.
Be first before your GP.
How can you be able to do that?
Because it's very important.
So what if I go over here and I'm going to keep altering this.
And anytime I alter what I need to do right now is I will go ahead and modify and we're going to say
modify.
And then the email which is a varchar.
So Varchar and that is 50.
Then we now say it comes after the last name.
So after the last underscore name curriculum guide, I'll make this last underscore name semicolon at
the end.
And this guy had on the run this.
And now we can confirm that that is okay.
So you can see students first name last name.
And we have email comes up then GP enroll date.
So in that way I can be able to modify this.
You can see how that comes and I can actually do that.
So maybe comes first.
So go ahead I'm going to come first.
Maybe that should be your assignment.
And you can also drop the email if you want to drop the email okay I'm going to also bring it to actually
come first.
If you want to come first, then what you need to do instead of you writing after students is very easy
to just see first.
All right, let me make this to be uppercase First place Omicron at the end and this guy had not run
this and check it out.
All right.
So my email has come.
First you see that.
So that's cool.
So the email has come first.
So I hope that is cool.
Now if you want to drop your email just a like you want to delete this email, you don't want it to
exist.
So also alter the table.
And what you need to do is just go ahead and drop the column and uh, email.
Then placed the record at the end and go ahead and run this query.
And you can see we have students ID first name, last name GP enroll date.
Right.
So let me go ahead and say I want to alter that.
I'll go ahead and say alter table and the number of table students.
And then we go ahead and say modify.
And then we select the column and there that is GP.
Then we cannot see decimal.
And I can increase this maybe like a five by three decimal place.
No problem.
That is cool.
And then place semicolon at the end.
And then we go ahead and run this query and check it out.
So we can see down here we are able to modify docs.
Go ahead and refresh this.
And now here you can see the GP decimal is five by three decimal place.
So that's cool.
So that is how you can be able to make some modifications to a table.
And I will go ahead and continue with that.
So let's go ahead and move to the next video lecture and see how to insert rows into a table.
Thank you and see you in the next video lecture.