1
00:00:00,090 --> 00:00:03,510
The next thing we have to talk about around tables are data types.

2
00:00:03,510 --> 00:00:11,130
So when we define the structure of a table, we're not only saying what column names we want, for example,

3
00:00:11,190 --> 00:00:19,350
you know, name, breed and age, but we also specify the types, what type of information is permitted

4
00:00:19,350 --> 00:00:20,430
in each column.

5
00:00:20,430 --> 00:00:22,180
And this is really, really important.

6
00:00:22,200 --> 00:00:29,250
Imagine we have our name, breed and age for the cat's table, where age is just left up to be whatever

7
00:00:29,250 --> 00:00:30,560
a user puts in there.

8
00:00:30,570 --> 00:00:38,520
So it could be a number one three or the word ten or I am young cat, whatever it is, there's no rules

9
00:00:38,520 --> 00:00:39,600
being enforced.

10
00:00:39,600 --> 00:00:44,490
It might make sense that it should be a number, but it doesn't say in our example at least that it

11
00:00:44,490 --> 00:00:47,460
has to be a number that leads to a lot of problems.

12
00:00:47,460 --> 00:00:54,720
If we try and then do stuff with our data, if we try and multiply it by seven to get a rough approximation,

13
00:00:54,870 --> 00:00:59,730
converting between cat years and human years, or vice versa, human years and cat years.

14
00:00:59,730 --> 00:01:05,040
To get the cat age, you multiply by seven, which is actually not really correct.

15
00:01:05,040 --> 00:01:07,290
That's a super simplification.

16
00:01:07,290 --> 00:01:09,300
It's not some easy formula.

17
00:01:09,300 --> 00:01:12,150
I looked it up recently, but this is good enough.

18
00:01:12,150 --> 00:01:13,350
I want to multiply it by seven.

19
00:01:13,350 --> 00:01:14,370
So one time seven.

20
00:01:14,370 --> 00:01:14,880
That's easy.

21
00:01:14,970 --> 00:01:16,440
Three times seven, That's easy.

22
00:01:16,770 --> 00:01:18,090
Ten times seven.

23
00:01:18,090 --> 00:01:19,110
We have a problem.

24
00:01:19,110 --> 00:01:20,910
The word ten times seven.

25
00:01:20,910 --> 00:01:22,590
And I am young cat time seven.

26
00:01:22,590 --> 00:01:23,670
It's just not going to work.

27
00:01:23,670 --> 00:01:27,360
So we need consistency of our types.

28
00:01:27,360 --> 00:01:35,010
We need not just to say what this column is called, but also what content it contains, what type of

29
00:01:35,010 --> 00:01:35,880
information.

30
00:01:35,880 --> 00:01:43,230
I want to say something like Name has to be text, breed has to be text, age has to be a number.

31
00:01:43,680 --> 00:01:47,700
So in the world of MySQL, we have a lot of different data types.

32
00:01:47,700 --> 00:01:49,910
It's honestly kind of overwhelming.

33
00:01:49,920 --> 00:01:52,620
The good news is that there's a handful you'll use a lot.

34
00:01:52,620 --> 00:01:56,580
But let me just show you, we have different types for numbers.

35
00:01:56,580 --> 00:01:59,340
You might think there's just a number type that's not true.

36
00:01:59,340 --> 00:02:04,530
Unfortunately, we have a type called integer or int, then we have small int and even smaller we have

37
00:02:04,530 --> 00:02:10,919
tiny int and then medium int and then big int and then decimal and then numeric and then float and then

38
00:02:10,919 --> 00:02:12,180
double and bit.

39
00:02:12,210 --> 00:02:18,180
It gets just absolutely crazy if you try and master or learn the, the differences between all of these

40
00:02:18,180 --> 00:02:18,690
up front.

41
00:02:18,690 --> 00:02:23,400
So don't, don't worry about it, but just know that there are a lot of different types.

42
00:02:23,500 --> 00:02:26,400
Same thing for string types or text types.

43
00:02:26,400 --> 00:02:28,830
We have char or car.

44
00:02:29,370 --> 00:02:31,890
I guess you should pronounce it car because it's character.

45
00:02:31,890 --> 00:02:35,280
But I've always said char, even if that's incorrect.

46
00:02:35,280 --> 00:02:37,920
Var char var car binary.

47
00:02:37,920 --> 00:02:47,280
Var binary blob tiny blob medium blob long blob text tiny text medium text long text enum.

48
00:02:47,280 --> 00:02:51,660
So these are all different categories of text information and there's differences.

49
00:02:51,660 --> 00:02:52,650
That's why they exist.

50
00:02:52,650 --> 00:02:55,320
But a lot of the differences are very slight.

51
00:02:55,320 --> 00:02:59,160
So we've got numeric types, string types, and we also have date types.

52
00:02:59,160 --> 00:03:03,210
So date, date, time, time stamp, time and year.

53
00:03:03,940 --> 00:03:05,260
It's a little crazy.

54
00:03:05,500 --> 00:03:10,540
If you ever get confused or you have questions, the first thing you should do is head to the docs.

55
00:03:10,540 --> 00:03:15,700
There's a page about data types and the documentation and the reference manual.

56
00:03:15,790 --> 00:03:21,520
So if you want to know more about, I don't know, string data types or numeric data types, click on

57
00:03:21,520 --> 00:03:26,650
that and then you'll see the different categories and then you can click to get more specific.

58
00:03:26,650 --> 00:03:32,500
If I want to learn more about small int, whatever that is compared to int, I can click here and it

59
00:03:32,500 --> 00:03:37,450
will tell me I can find out the rules and we're going to dive into some of this stuff later in the course.

60
00:03:37,450 --> 00:03:39,970
So for now we really don't need to worry.

61
00:03:39,970 --> 00:03:44,500
You should just know that there are different categories of information, different types, and there's

62
00:03:44,500 --> 00:03:51,730
two specifically that we're going to work with right now Integer or int for short and var kar or var

63
00:03:51,730 --> 00:03:56,410
char, which is a text or a string data type for textual information.

64
00:03:56,410 --> 00:03:59,260
So let's talk a bit more about int, int or integer.

65
00:03:59,260 --> 00:04:02,830
You can write it either way, but int is nice and short is a whole number.

66
00:04:02,830 --> 00:04:07,990
So no decimals and it has a maximum value of this number right here.

67
00:04:07,990 --> 00:04:13,720
But this is a maximum signed value, meaning that we could also have negative this value.

68
00:04:13,720 --> 00:04:19,540
So negative or positive, you can have a larger maximum value if you set it up in such a way that you

69
00:04:19,540 --> 00:04:20,920
don't allow signed values.

70
00:04:20,920 --> 00:04:23,950
It's unsigned, but we really don't need to worry about that.

71
00:04:24,250 --> 00:04:26,650
I just need to put that in there to be specific.

72
00:04:26,650 --> 00:04:31,180
But at the end of the day, it's a whole number and unless you're dealing with really big whole numbers,

73
00:04:31,180 --> 00:04:33,610
you really don't need to worry about the maximum size.

74
00:04:33,610 --> 00:04:43,870
So something like 12, that's a valid int -9999 valid int so is zero, so is 3145677 or 42.

75
00:04:44,050 --> 00:04:45,640
Those are all integers.

76
00:04:45,640 --> 00:04:52,360
Now we have var char or var kar, which is a variable length string, that's the var parts.

77
00:04:52,360 --> 00:04:58,390
There's also just a data type called car or char that is not variable length and we'll see that later.

78
00:04:58,750 --> 00:05:03,760
So when I say variable length, that means that we can store something that is this many characters,

79
00:05:03,760 --> 00:05:08,050
but is that four or five, six, seven, eight characters long or this many characters?

80
00:05:08,050 --> 00:05:13,780
Now this is a number, but notice it's in quotes, meaning it is treated as text or this many characters

81
00:05:13,780 --> 00:05:19,780
or a single character or a whole sentence, 26 plus characters, way more than 26.

82
00:05:19,780 --> 00:05:23,830
Whatever a number of characters this is, it's a variable length.

83
00:05:24,130 --> 00:05:30,490
So var is really commonly used because a lot of the time our textual information does vary in length.

84
00:05:30,490 --> 00:05:32,260
Think of people's usernames.

85
00:05:32,410 --> 00:05:34,540
Somebody might have the username colt.

86
00:05:34,540 --> 00:05:35,170
That's nice.

87
00:05:35,170 --> 00:05:35,950
They were there early.

88
00:05:35,950 --> 00:05:42,010
It's for characters, but somebody else might have to have Colt four or five, six, seven and so on.

89
00:05:42,010 --> 00:05:43,570
It's more characters.

90
00:05:43,570 --> 00:05:48,100
So that's bar car an INT the two basic data types we're going to start with.

91
00:05:48,100 --> 00:05:54,310
Now, the next thing you need to know is that when we create a table and we assign the data types with

92
00:05:54,320 --> 00:05:59,590
VAR car, we can actually specify a maximum number of characters allowed.

93
00:05:59,590 --> 00:06:07,390
So with var card or var char, I can say maximum of 100 characters for name and let's say for breed

94
00:06:07,390 --> 00:06:08,350
the same thing.

95
00:06:08,440 --> 00:06:10,360
Maybe I want it smaller.

96
00:06:10,390 --> 00:06:11,170
It's hard to say.

97
00:06:11,440 --> 00:06:13,930
Is there going to be a cat name that's 100 characters or more?

98
00:06:13,960 --> 00:06:15,460
Maybe, maybe not.

99
00:06:15,460 --> 00:06:22,720
But this allows me to specify a maximum size so it can still vary between zero and 100 characters,

100
00:06:22,720 --> 00:06:29,320
but the maximum is 100 characters that will store in this column for each row and then for int, we'll

101
00:06:29,320 --> 00:06:34,510
just say int and this just says an integer of any size, assuming it fits within those bounds that I

102
00:06:34,510 --> 00:06:39,370
showed you that really large number, we can go anywhere up to that size.

103
00:06:39,370 --> 00:06:41,230
So for age it's going to be fine.

104
00:06:41,380 --> 00:06:46,960
Although something we might want to consider is is age best stored as a whole number?

105
00:06:46,960 --> 00:06:48,700
What about fractions or decimals?

106
00:06:48,700 --> 00:06:53,830
Because right now that is not an option if we're using integer, but that's for another section coming

107
00:06:53,830 --> 00:06:54,070
up.

108
00:06:54,070 --> 00:06:56,590
So I'm going to stop here because it's a long video.

109
00:06:56,860 --> 00:06:58,090
We covered a lot.

110
00:06:58,090 --> 00:07:04,450
The basic concept is that there are all these different data types in the world with my SQL ten plus

111
00:07:04,450 --> 00:07:12,430
number data types and ten plus string or text data types, not to mention dates and times and even other

112
00:07:12,430 --> 00:07:14,050
things like spatial data types.

113
00:07:14,050 --> 00:07:19,630
These are all different types that we can assign to columns in a table and then the database.

114
00:07:19,630 --> 00:07:21,940
My SQL will enforce those types.

115
00:07:22,150 --> 00:07:28,090
So with VAR car, that's the one we're focusing on for text four Now it represents or it stores text

116
00:07:28,090 --> 00:07:32,410
of variable length up to whatever size we specify in those prints.

117
00:07:32,410 --> 00:07:35,290
And then int we'll store whole numbers.

118
00:07:36,040 --> 00:07:38,170
Next up, we've got a quick little activity.

