The next thing we have to talk about around tables are data types.
So when we define the structure of a table, we're not only saying what column names we want, for example,
you know, name, breed and age, but we also specify the types, what type of information is permitted
in each column.
And this is really, really important.
Imagine we have our name, breed and age for the cat's table, where age is just left up to be whatever
a user puts in there.
So it could be a number one three or the word ten or I am young cat, whatever it is, there's no rules
being enforced.
It might make sense that it should be a number, but it doesn't say in our example at least that it
has to be a number that leads to a lot of problems.
If we try and then do stuff with our data, if we try and multiply it by seven to get a rough approximation,
converting between cat years and human years, or vice versa, human years and cat years.
To get the cat age, you multiply by seven, which is actually not really correct.
That's a super simplification.
It's not some easy formula.
I looked it up recently, but this is good enough.
I want to multiply it by seven.
So one time seven.
That's easy.
Three times seven, That's easy.
Ten times seven.
We have a problem.
The word ten times seven.
And I am young cat time seven.
It's just not going to work.
So we need consistency of our types.
We need not just to say what this column is called, but also what content it contains, what type of
information.
I want to say something like Name has to be text, breed has to be text, age has to be a number.
So in the world of MySQL, we have a lot of different data types.
It's honestly kind of overwhelming.
The good news is that there's a handful you'll use a lot.
But let me just show you, we have different types for numbers.
You might think there's just a number type that's not true.
Unfortunately, we have a type called integer or int, then we have small int and even smaller we have
tiny int and then medium int and then big int and then decimal and then numeric and then float and then
double and bit.
It gets just absolutely crazy if you try and master or learn the, the differences between all of these
up front.
So don't, don't worry about it, but just know that there are a lot of different types.
Same thing for string types or text types.
We have char or car.
I guess you should pronounce it car because it's character.
But I've always said char, even if that's incorrect.
Var char var car binary.
Var binary blob tiny blob medium blob long blob text tiny text medium text long text enum.
So these are all different categories of text information and there's differences.
That's why they exist.
But a lot of the differences are very slight.
So we've got numeric types, string types, and we also have date types.
So date, date, time, time stamp, time and year.
It's a little crazy.
If you ever get confused or you have questions, the first thing you should do is head to the docs.
There's a page about data types and the documentation and the reference manual.
So if you want to know more about, I don't know, string data types or numeric data types, click on
that and then you'll see the different categories and then you can click to get more specific.
If I want to learn more about small int, whatever that is compared to int, I can click here and it
will tell me I can find out the rules and we're going to dive into some of this stuff later in the course.
So for now we really don't need to worry.
You should just know that there are different categories of information, different types, and there's
two specifically that we're going to work with right now Integer or int for short and var kar or var
char, which is a text or a string data type for textual information.
So let's talk a bit more about int, int or integer.
You can write it either way, but int is nice and short is a whole number.
So no decimals and it has a maximum value of this number right here.
But this is a maximum signed value, meaning that we could also have negative this value.
So negative or positive, you can have a larger maximum value if you set it up in such a way that you
don't allow signed values.
It's unsigned, but we really don't need to worry about that.
I just need to put that in there to be specific.
But at the end of the day, it's a whole number and unless you're dealing with really big whole numbers,
you really don't need to worry about the maximum size.
So something like 12, that's a valid int -9999 valid int so is zero, so is 3145677 or 42.
Those are all integers.
Now we have var char or var kar, which is a variable length string, that's the var parts.
There's also just a data type called car or char that is not variable length and we'll see that later.
So when I say variable length, that means that we can store something that is this many characters,
but is that four or five, six, seven, eight characters long or this many characters?
Now this is a number, but notice it's in quotes, meaning it is treated as text or this many characters
or a single character or a whole sentence, 26 plus characters, way more than 26.
Whatever a number of characters this is, it's a variable length.
So var is really commonly used because a lot of the time our textual information does vary in length.
Think of people's usernames.
Somebody might have the username colt.
That's nice.
They were there early.
It's for characters, but somebody else might have to have Colt four or five, six, seven and so on.
It's more characters.
So that's bar car an INT the two basic data types we're going to start with.
Now, the next thing you need to know is that when we create a table and we assign the data types with
VAR car, we can actually specify a maximum number of characters allowed.
So with var card or var char, I can say maximum of 100 characters for name and let's say for breed
the same thing.
Maybe I want it smaller.
It's hard to say.
Is there going to be a cat name that's 100 characters or more?
Maybe, maybe not.
But this allows me to specify a maximum size so it can still vary between zero and 100 characters,
but the maximum is 100 characters that will store in this column for each row and then for int, we'll
just say int and this just says an integer of any size, assuming it fits within those bounds that I
showed you that really large number, we can go anywhere up to that size.
So for age it's going to be fine.
Although something we might want to consider is is age best stored as a whole number?
What about fractions or decimals?
Because right now that is not an option if we're using integer, but that's for another section coming
up.
So I'm going to stop here because it's a long video.
We covered a lot.
The basic concept is that there are all these different data types in the world with my SQL ten plus
number data types and ten plus string or text data types, not to mention dates and times and even other
things like spatial data types.
These are all different types that we can assign to columns in a table and then the database.
My SQL will enforce those types.
So with VAR car, that's the one we're focusing on for text four Now it represents or it stores text
of variable length up to whatever size we specify in those prints.
And then int we'll store whole numbers.
Next up, we've got a quick little activity.