WEBVTT

00:00.120 --> 00:06.870
So the next thing we need to discuss around tables are data types data types are really really important

00:07.260 --> 00:12.000
and to show you what I mean and first of all when I'm talking about when I say data types Let's return

00:12.000 --> 00:14.700
back to our catch table.

00:14.970 --> 00:19.380
So we have these three headers in three columns name breed and age.

00:20.040 --> 00:23.220
And here's an example I changed some of the data just a little bit.

00:23.220 --> 00:29.320
So the names are the same the breeds are the same but if you look over at age Blue is one year old rock

00:29.450 --> 00:30.640
it is three.

00:31.020 --> 00:37.310
But Montie now is 10 the word 10 and Sam is crazy.

00:37.380 --> 00:39.510
Sam's age is I am young.

00:39.540 --> 00:40.130
Correct.

00:40.170 --> 00:44.370
So what I'm trying to illustrate here is that we have inconsistent data.

00:44.730 --> 00:47.130
This is all text in text.

00:47.130 --> 00:52.170
But here we've got numbers mixed with text and that is not good and it's actually not allowed in school

00:52.170 --> 00:52.860
at all.

00:52.860 --> 00:59.750
When you create a new table you actually have to specify name has to be text.

00:59.760 --> 01:01.040
Breed has to be text.

01:01.050 --> 01:05.890
Age has to be a number and there are a whole bunch of different data types.

01:06.180 --> 01:10.070
It's not just text and number in fact those aren't even data types.

01:10.080 --> 01:12.440
Those are just what I'm calling them the English version.

01:12.450 --> 01:18.060
But you'll see them in just a second but to illustrate why it's so important that your data matches

01:18.420 --> 01:22.960
that you don't have this inconsistent data and why sequel forces you to do this.

01:23.460 --> 01:25.210
Here's a little example.

01:25.710 --> 01:34.350
So let's say that you have this data in your database in a table where hypothetically in a fictional

01:34.350 --> 01:37.290
world you can have data that isn't all matching.

01:37.290 --> 01:42.720
So we have this you know numeric data mixed with text under age.

01:42.720 --> 01:47.820
So let's say I wanted to make a really really simple app that would take each cat's age in the database

01:48.300 --> 01:53.570
and then print out the converted or equivalent cat age.

01:53.610 --> 01:59.910
So from human years to cat years basically which is sort of interesting actually in making these slides.

02:00.000 --> 02:06.810
I learned quite a bit about how you calculate cat age because for dogs or this colloquialism you can

02:06.810 --> 02:08.380
just multiply it by seven.

02:08.430 --> 02:11.060
For cats it's a little more complex.

02:11.280 --> 02:14.040
Apparently it's not linear.

02:14.040 --> 02:19.460
So if you look at the scale when a cat is 2 months old it's three years in human years.

02:19.680 --> 02:26.200
But then they get to two years old but suddenly 24 and when they're 14 at 72 so it's not consistent.

02:26.220 --> 02:30.210
So I just decided you know what let's just go with multiplying by 7.

02:30.240 --> 02:31.460
It really doesn't matter.

02:31.830 --> 02:36.330
So our app takes the age of blue multiplies by seven no problem.

02:36.360 --> 02:37.700
Our app takes three.

02:37.740 --> 02:38.720
Multiply that by seven.

02:38.730 --> 02:42.230
No problem but it has no idea what to do here.

02:42.420 --> 02:45.710
Our code doesn't expect text and it can't do that.

02:45.790 --> 02:48.670
The same thing with I am young cat.

02:48.710 --> 02:50.020
TIME 7.

02:50.100 --> 02:51.090
It doesn't even know what to do.

02:51.100 --> 02:52.260
It just freaks out.

02:52.500 --> 02:55.000
So really trivial stupid example I know.

02:55.140 --> 03:00.560
But the idea here is important that we have to have these data types are established and that my Eskew

03:00.740 --> 03:02.070
will enforce them.

03:02.070 --> 03:08.910
So when we create tables we have to say exactly what data type we're looking for because this type of

03:08.910 --> 03:11.880
situation is really really not good.

03:11.880 --> 03:13.300
Also known as bad.

03:13.710 --> 03:20.460
So returning to our catch table when we're creating it we'll have to say this must be text breed must

03:20.460 --> 03:24.590
be text and age must be a number.

03:24.640 --> 03:28.910
So in reality there are a lot of different my Escuela data types.

03:29.260 --> 03:32.970
Like I said text and number are not real data types.

03:32.980 --> 03:38.950
In fact there are a ton in my opinion too many and it gets pretty confusing especially when you're just

03:38.950 --> 03:39.400
starting out.

03:39.400 --> 03:43.130
It can be intimidating just to show you exactly what I'm talking about.

03:43.360 --> 03:45.730
I put together a list of all the different data types.

03:45.850 --> 03:51.430
So all the numeric types basically the different ways of representing numbers we've got.

03:51.430 --> 03:59.090
It's small it's tiny and medium and big and decimal numeric float double.

03:59.150 --> 04:01.890
But then under string types.

04:01.900 --> 04:10.600
So these are ways of representing text basically char var char binary var binary blob tiny medium blob

04:10.600 --> 04:16.080
long blob text tiny text medium text long text and then you know.

04:16.540 --> 04:20.190
And then finally we've got data types of different ways of representing dates.

04:20.320 --> 04:24.560
We've got date date time time stamp time and year.

04:24.760 --> 04:27.810
So yeah it's kind of crazy.

04:27.850 --> 04:32.740
I know fortunately you don't have to know all of those at any given time.

04:32.740 --> 04:34.060
Absolutely not.

04:34.060 --> 04:39.010
I had to spend a decent amount of time even digging through the documentation just to find all of these

04:39.460 --> 04:44.110
because the reality is you don't use them most of the time or you don't use all of them.

04:44.890 --> 04:48.570
You figure out which ones you need depending on a given situation.

04:48.730 --> 04:54.280
You use a subset normally that you're comfortable with and then eventually you may have to switch things

04:54.280 --> 05:00.430
out and change from using a medium into a big bigot are actually more realistically an end to a big

05:00.430 --> 05:01.710
event or something like that.

05:02.140 --> 05:04.460
But we'll get there for now.

05:04.780 --> 05:06.180
We're going to hope that it's crazy.

05:06.400 --> 05:09.360
And we're just going to whittle it down and focus on two.

05:09.470 --> 05:12.500
The first one is it for a numeric type.

05:12.520 --> 05:14.970
And then Vardar for our string type.

05:15.040 --> 05:19.720
So to represent numbers we're working with Ant and that's represent text strings.

05:19.780 --> 05:21.240
Work with var char.

05:21.820 --> 05:23.190
So we'll start off with it.

05:23.500 --> 05:25.340
So it represents a whole number.

05:25.360 --> 05:26.980
So we can't use it for decimals.

05:28.290 --> 05:32.240
And it ranges up to this gigantic number here.

05:32.490 --> 05:34.390
Basically it's big.

05:34.470 --> 05:39.180
However if you need to store numbers larger than that that's when you can start looking into some of

05:39.180 --> 05:41.620
these other data types but like bigot.

05:41.640 --> 05:47.520
But we're not going to worry about that because for now we're storing things like cat age.

05:47.580 --> 05:49.110
So this is an it.

05:49.290 --> 05:55.970
Here's another and it can be negative or zero or big or 42.

05:55.970 --> 06:04.060
So that's pretty much it to its then Vardar is a way of representing text or strings and it's variable

06:04.060 --> 06:04.650
length.

06:04.730 --> 06:09.060
So you may have noticed that there was char on there and Vardar.

06:09.070 --> 06:11.520
Well char is a fixed length.

06:11.620 --> 06:15.530
So that means that everything in that column has to be the same length.

06:15.730 --> 06:17.620
It has to be 10 characters or something.

06:17.710 --> 06:24.370
But Vardar allows it to have variation in that which is what we want most of the time and it's between

06:24.370 --> 06:26.740
1 and 255 characters.

06:27.850 --> 06:35.320
So things like coffee or negative nine thousand nine hundred ninety nine string in quotes.

06:35.530 --> 06:42.700
So it's not a number or this whatever this is or capital L or a sentence as long as it's fewer than

06:42.700 --> 06:44.630
255 characters.

06:44.680 --> 06:51.100
So returning to our acads table we would say that name which must be text would be Vardar.

06:51.310 --> 06:54.900
And notice that I have these parentheses here and a number inside.

06:54.910 --> 06:58.310
So when you use Farje are you have to specify a maximum length.

06:58.330 --> 07:00.550
So in my case I chose 100.

07:00.670 --> 07:06.670
I could go up to 255 but I just don't want to have any giant names but that's all that it does here.

07:06.730 --> 07:09.620
So it specifies where the cutoff point is.

07:09.620 --> 07:15.700
And if I go beyond 100 characters if I write 300 or 200 characters all that will be stored is from the

07:15.700 --> 07:18.130
first character to the one hundredth character.

07:18.340 --> 07:25.750
So three I did the same thing Vardar and I did a 100 again but that could change if we wanted them.

07:25.780 --> 07:32.320
If we want to restrict breeds to be shorter if we could change it to be 50 characters and then for age

07:32.320 --> 07:35.340
which must be a number we just use it.

07:35.440 --> 07:38.260
We're just working with whole numbers we're not going to worry about.

07:38.260 --> 07:42.230
My cat is one point 2 years old or anything like that.

07:42.300 --> 07:42.680
OK.

07:42.700 --> 07:45.150
So that's all we're going to do for now with data types.

07:45.220 --> 07:46.780
Basically high level overview.

07:46.840 --> 07:50.450
And we saw two of them in particular char and it.

07:50.470 --> 07:52.150
Next up we have a really quick activity.
