WEBVTT

00:00.090 --> 00:04.150
Next up we're going to focus our time on learning to create data.

00:04.170 --> 00:08.730
How do we add or insert data into the tables that we've already made.

00:08.730 --> 00:12.870
This is another one of the most important and most commonly used commands.

00:12.930 --> 00:18.310
When you're working with databases obviously it's really important to have a way to get your data in

00:18.310 --> 00:19.560
the database.

00:19.620 --> 00:24.180
So we'll be using what we learn here throughout the rest of the course and you could say that for everything

00:24.300 --> 00:25.400
else we've learned so far.

00:25.410 --> 00:36.930
But in particular this command insert her insert into the syntax here is insert into and then the name

00:36.930 --> 00:38.530
of the table cats.

00:38.550 --> 00:41.670
In our case and then it gets a little weird after that.

00:41.670 --> 00:45.700
So let's just focus on that first insert into and then the table name.

00:46.290 --> 00:52.620
Then afterwards in parentheses we're specifying the columns that we are going to insert.

00:52.830 --> 00:55.710
So I'm saying I'm going to give you a name comma.

00:55.710 --> 01:02.890
I'm going to give you an age and then down here I have values which is another keyword specifying that.

01:02.910 --> 01:04.770
OK I told you and giving you a name and an age.

01:04.770 --> 01:06.090
Here they are.

01:06.090 --> 01:09.840
The name is Jetson and the age is seven.

01:09.960 --> 01:15.050
So these do need to match names first Jetson age or second seven.

01:15.120 --> 01:17.430
Before we go try it out in cloud 9.

01:17.590 --> 01:22.170
Just want to show you that I wrote it this way mainly because it looks best on a slide.

01:22.740 --> 01:30.900
You can do it on one line so insert into cat's name and age the values Jetson and seven or you can do

01:30.900 --> 01:31.590
it like this.

01:31.590 --> 01:35.010
And this is actually a lot of people's preferred way of writing it.

01:35.070 --> 01:40.500
But this is a huge pain to enter into the shell this way where you have to you know space things manually.

01:40.710 --> 01:46.680
But when we start working with individual sequence files where we'll save our own code basically into

01:46.680 --> 01:50.850
these separate files in a text editor and we can space them out how we want.

01:50.850 --> 01:55.560
This is definitely the preferrable way but we're going to work with this.

01:55.560 --> 02:01.770
I just like this when I'm presenting and when I'm teaching it it's a mix of readability but also it's

02:01.770 --> 02:03.800
not so laborious like this.

02:04.280 --> 02:04.790
Okay.

02:05.010 --> 02:12.270
And just to hit this point home the order that we write these column names matters.

02:12.270 --> 02:19.410
So if I say insert into cats and I say age is coming first and then name I have to provide age first

02:19.500 --> 02:20.900
and then name.

02:21.210 --> 02:23.560
So it doesn't matter which order you use.

02:23.650 --> 02:27.210
But whatever you establish appear you have to follow through with.

02:27.450 --> 02:28.850
Otherwise it will try.

02:28.850 --> 02:32.010
If you had this reversed it would try an aside.

02:32.100 --> 02:38.430
It was trying to sign Victoria to age and 12 to name and that's going to be a problem because we have

02:38.430 --> 02:43.830
these strict data types where things are supposed to be numbers and strings and so if you mix them up

02:43.830 --> 02:47.210
it's problematic not to mention that it makes no sense.

02:47.250 --> 02:49.790
So let's give it a shot in cloud night.

02:50.620 --> 02:52.120
I'll make some space here.

02:52.650 --> 02:59.210
And the first thing we need to do is actually recreate a table because right now I don't have a cat's

02:59.210 --> 02:59.690
table.

02:59.760 --> 03:02.560
I deleted it because I showed you how the beat works.

03:02.640 --> 03:08.600
So let's recreate that create table cats and it's going to have a name.

03:08.700 --> 03:19.310
So far char 50 comma age is going to be it just like that perfect.

03:19.420 --> 03:21.640
So now we'll use the insert into command.

03:21.640 --> 03:22.580
We just learned.

03:22.710 --> 03:33.880
So we will insert a new cat insert into cats and I'll start with name and then age and then I'll go

03:33.880 --> 03:34.710
to a new line.

03:34.750 --> 03:40.240
I don't have to but I like to values and the values will put in.

03:40.270 --> 03:41.890
Let's say for name.

03:42.010 --> 03:43.610
Let's work with my cat.

03:43.660 --> 03:51.580
Blue comma and her age is somewhere between one and two were to leave it as one semi-colon will hit

03:51.580 --> 03:53.170
enter.

03:53.170 --> 03:55.150
We get our queery Okay.

03:55.540 --> 03:57.400
This time it says one row affected.

03:57.420 --> 04:02.830
He may have noticed that everything else we've done so far has said zero rows affected and I think that's

04:02.830 --> 04:04.030
pretty self-explanatory.

04:04.030 --> 04:09.880
We haven't had any rows of data yet so all of these commands have returned 0 rows affected.

04:09.880 --> 04:16.390
Now we actually have created something we've added data to a table and it says one row affected.

04:16.930 --> 04:22.360
And before we move on let's insert one more cat here and this time will switch up the order.

04:22.510 --> 04:26.470
Insert into cats and I'll do it on one line.

04:26.530 --> 04:30.440
Age comma name and then are values.

04:30.820 --> 04:39.450
Let's say the age for this cat will be 11 and the name will be Draco.

04:40.200 --> 04:42.440
All right.

04:42.740 --> 04:45.210
And we also get one row affected.

04:45.240 --> 04:49.310
So next logical question might be how do we see the data.

04:49.310 --> 04:51.340
How do we know that it's in there correctly.

04:51.350 --> 04:55.270
Basically the same thing that you might have asked when we saw how to create a table.

04:55.310 --> 04:56.510
How do we check our work.

04:56.730 --> 04:58.760
Well we've created data in a table.

04:58.760 --> 05:01.920
How do we check our work and we'll see that in the next video.

05:02.000 --> 05:02.870
Sorry for the cliffhanger.
