So the next thing we need to discuss around tables are data types data types are really really important
and to show you what I mean and first of all when I'm talking about when I say data types Let's return
back to our catch table.
So we have these three headers in three columns name breed and age.
And here's an example I changed some of the data just a little bit.
So the names are the same the breeds are the same but if you look over at age Blue is one year old rock
it is three.
But Montie now is 10 the word 10 and Sam is crazy.
Sam's age is I am young.
Correct.
So what I'm trying to illustrate here is that we have inconsistent data.
This is all text in text.
But here we've got numbers mixed with text and that is not good and it's actually not allowed in school
at all.
When you create a new table you actually have to specify name has to be text.
Breed has to be text.
Age has to be a number and there are a whole bunch of different data types.
It's not just text and number in fact those aren't even data types.
Those are just what I'm calling them the English version.
But you'll see them in just a second but to illustrate why it's so important that your data matches
that you don't have this inconsistent data and why sequel forces you to do this.
Here's a little example.
So let's say that you have this data in your database in a table where hypothetically in a fictional
world you can have data that isn't all matching.
So we have this you know numeric data mixed with text under age.
So let's say I wanted to make a really really simple app that would take each cat's age in the database
and then print out the converted or equivalent cat age.
So from human years to cat years basically which is sort of interesting actually in making these slides.
I learned quite a bit about how you calculate cat age because for dogs or this colloquialism you can
just multiply it by seven.
For cats it's a little more complex.
Apparently it's not linear.
So if you look at the scale when a cat is 2 months old it's three years in human years.
But then they get to two years old but suddenly 24 and when they're 14 at 72 so it's not consistent.
So I just decided you know what let's just go with multiplying by 7.
It really doesn't matter.
So our app takes the age of blue multiplies by seven no problem.
Our app takes three.
Multiply that by seven.
No problem but it has no idea what to do here.
Our code doesn't expect text and it can't do that.
The same thing with I am young cat.
TIME 7.
It doesn't even know what to do.
It just freaks out.
So really trivial stupid example I know.
But the idea here is important that we have to have these data types are established and that my Eskew
will enforce them.
So when we create tables we have to say exactly what data type we're looking for because this type of
situation is really really not good.
Also known as bad.
So returning to our catch table when we're creating it we'll have to say this must be text breed must
be text and age must be a number.
So in reality there are a lot of different my Escuela data types.
Like I said text and number are not real data types.
In fact there are a ton in my opinion too many and it gets pretty confusing especially when you're just
starting out.
It can be intimidating just to show you exactly what I'm talking about.
I put together a list of all the different data types.
So all the numeric types basically the different ways of representing numbers we've got.
It's small it's tiny and medium and big and decimal numeric float double.
But then under string types.
So these are ways of representing text basically char var char binary var binary blob tiny medium blob
long blob text tiny text medium text long text and then you know.
And then finally we've got data types of different ways of representing dates.
We've got date date time time stamp time and year.
So yeah it's kind of crazy.
I know fortunately you don't have to know all of those at any given time.
Absolutely not.
I had to spend a decent amount of time even digging through the documentation just to find all of these
because the reality is you don't use them most of the time or you don't use all of them.
You figure out which ones you need depending on a given situation.
You use a subset normally that you're comfortable with and then eventually you may have to switch things
out and change from using a medium into a big bigot are actually more realistically an end to a big
event or something like that.
But we'll get there for now.
We're going to hope that it's crazy.
And we're just going to whittle it down and focus on two.
The first one is it for a numeric type.
And then Vardar for our string type.
So to represent numbers we're working with Ant and that's represent text strings.
Work with var char.
So we'll start off with it.
So it represents a whole number.
So we can't use it for decimals.
And it ranges up to this gigantic number here.
Basically it's big.
However if you need to store numbers larger than that that's when you can start looking into some of
these other data types but like bigot.
But we're not going to worry about that because for now we're storing things like cat age.
So this is an it.
Here's another and it can be negative or zero or big or 42.
So that's pretty much it to its then Vardar is a way of representing text or strings and it's variable
length.
So you may have noticed that there was char on there and Vardar.
Well char is a fixed length.
So that means that everything in that column has to be the same length.
It has to be 10 characters or something.
But Vardar allows it to have variation in that which is what we want most of the time and it's between
1 and 255 characters.
So things like coffee or negative nine thousand nine hundred ninety nine string in quotes.
So it's not a number or this whatever this is or capital L or a sentence as long as it's fewer than
255 characters.
So returning to our acads table we would say that name which must be text would be Vardar.
And notice that I have these parentheses here and a number inside.
So when you use Farje are you have to specify a maximum length.
So in my case I chose 100.
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.
So it specifies where the cutoff point is.
And if I go beyond 100 characters if I write 300 or 200 characters all that will be stored is from the
first character to the one hundredth character.
So three I did the same thing Vardar and I did a 100 again but that could change if we wanted them.
If we want to restrict breeds to be shorter if we could change it to be 50 characters and then for age
which must be a number we just use it.
We're just working with whole numbers we're not going to worry about.
My cat is one point 2 years old or anything like that.
OK.
So that's all we're going to do for now with data types.
Basically high level overview.
And we saw two of them in particular char and it.
Next up we have a really quick activity.