Next up we're going to focus our time on learning to create data.
How do we add or insert data into the tables that we've already made.
This is another one of the most important and most commonly used commands.
When you're working with databases obviously it's really important to have a way to get your data in
the database.
So we'll be using what we learn here throughout the rest of the course and you could say that for everything
else we've learned so far.
But in particular this command insert her insert into the syntax here is insert into and then the name
of the table cats.
In our case and then it gets a little weird after that.
So let's just focus on that first insert into and then the table name.
Then afterwards in parentheses we're specifying the columns that we are going to insert.
So I'm saying I'm going to give you a name comma.
I'm going to give you an age and then down here I have values which is another keyword specifying that.
OK I told you and giving you a name and an age.
Here they are.
The name is Jetson and the age is seven.
So these do need to match names first Jetson age or second seven.
Before we go try it out in cloud 9.
Just want to show you that I wrote it this way mainly because it looks best on a slide.
You can do it on one line so insert into cat's name and age the values Jetson and seven or you can do
it like this.
And this is actually a lot of people's preferred way of writing it.
But this is a huge pain to enter into the shell this way where you have to you know space things manually.
But when we start working with individual sequence files where we'll save our own code basically into
these separate files in a text editor and we can space them out how we want.
This is definitely the preferrable way but we're going to work with this.
I just like this when I'm presenting and when I'm teaching it it's a mix of readability but also it's
not so laborious like this.
Okay.
And just to hit this point home the order that we write these column names matters.
So if I say insert into cats and I say age is coming first and then name I have to provide age first
and then name.
So it doesn't matter which order you use.
But whatever you establish appear you have to follow through with.
Otherwise it will try.
If you had this reversed it would try an aside.
It was trying to sign Victoria to age and 12 to name and that's going to be a problem because we have
these strict data types where things are supposed to be numbers and strings and so if you mix them up
it's problematic not to mention that it makes no sense.
So let's give it a shot in cloud night.
I'll make some space here.
And the first thing we need to do is actually recreate a table because right now I don't have a cat's
table.
I deleted it because I showed you how the beat works.
So let's recreate that create table cats and it's going to have a name.
So far char 50 comma age is going to be it just like that perfect.
So now we'll use the insert into command.
We just learned.
So we will insert a new cat insert into cats and I'll start with name and then age and then I'll go
to a new line.
I don't have to but I like to values and the values will put in.
Let's say for name.
Let's work with my cat.
Blue comma and her age is somewhere between one and two were to leave it as one semi-colon will hit
enter.
We get our queery Okay.
This time it says one row affected.
He may have noticed that everything else we've done so far has said zero rows affected and I think that's
pretty self-explanatory.
We haven't had any rows of data yet so all of these commands have returned 0 rows affected.
Now we actually have created something we've added data to a table and it says one row affected.
And before we move on let's insert one more cat here and this time will switch up the order.
Insert into cats and I'll do it on one line.
Age comma name and then are values.
Let's say the age for this cat will be 11 and the name will be Draco.
All right.
And we also get one row affected.
So next logical question might be how do we see the data.
How do we know that it's in there correctly.
Basically the same thing that you might have asked when we saw how to create a table.
How do we check our work.
Well we've created data in a table.
How do we check our work and we'll see that in the next video.
Sorry for the cliffhanger.