1 00:00:00,150 --> 00:00:03,510 The next group of data types will cover are numeric types. 2 00:00:03,510 --> 00:00:05,340 And of course, we've already seen one. 3 00:00:05,340 --> 00:00:07,860 We've been using it all over the place. 4 00:00:07,860 --> 00:00:13,920 It stores whole numbers and we've been using the plain regular variety of INT, But recall from the 5 00:00:13,920 --> 00:00:16,770 docs that there's integer and int, those are the same. 6 00:00:16,770 --> 00:00:21,330 It's just a shorter version of the, it's a short way of referencing integer. 7 00:00:21,330 --> 00:00:25,440 They mean the same thing, but there's also a small into tiny and medium int and big int. 8 00:00:25,620 --> 00:00:30,390 So I don't want to dive too much into into the details, but it's actually quite simple. 9 00:00:30,390 --> 00:00:35,970 The difference comes down to how large of an integer you can store with each type. 10 00:00:35,970 --> 00:00:40,230 It's all about optimising storage and how much memory things take up. 11 00:00:40,470 --> 00:00:47,730 So a regular integer or int the one we've been using takes up four bytes according to this table and 12 00:00:47,730 --> 00:00:49,470 the maximum signed value. 13 00:00:49,470 --> 00:00:53,970 Remember we talked about the signed versus unsigned signs means it could be negative or positive. 14 00:00:54,000 --> 00:00:58,780 Is this number here, which is what, thousand 100,000? 15 00:00:58,800 --> 00:00:58,950 Right. 16 00:00:58,950 --> 00:00:59,670 So that's. 17 00:01:01,360 --> 00:01:03,280 Which is 2 billion. 18 00:01:03,310 --> 00:01:05,830 It's hard without the commas, but I think it's 2 billion. 19 00:01:05,830 --> 00:01:09,340 147,483,647. 20 00:01:11,320 --> 00:01:13,690 That is the maximum signed value. 21 00:01:13,690 --> 00:01:17,620 So the minimum would then be this -2.1 billion. 22 00:01:18,460 --> 00:01:26,050 And then if we compare that to some of these other integers, like tiny int, tiny int can go from -128 23 00:01:26,050 --> 00:01:27,990 up to 127. 24 00:01:28,000 --> 00:01:34,210 So if we were storing something small like the number of children somebody has or the number of dependents 25 00:01:34,210 --> 00:01:40,240 on their tax returns or something horrible like that, tiny, there's no reason to have this much space 26 00:01:40,240 --> 00:01:42,730 allotted, which would be four bytes. 27 00:01:43,300 --> 00:01:48,940 Why not just stick to one byte and have a small integer or technically a tiny int? 28 00:01:49,180 --> 00:01:50,740 I can show that really quickly. 29 00:01:50,740 --> 00:01:51,880 I'll do it over here. 30 00:01:52,690 --> 00:01:56,920 It's not going to look any different to us really, but I'll create a table. 31 00:01:57,160 --> 00:02:00,400 Create table, let's call it parent. 32 00:02:00,490 --> 00:02:05,740 And then we just have children, which will be a tiny int. 33 00:02:07,080 --> 00:02:12,570 And if I insert into parent, we don't have any other information about a parent, just the number of 34 00:02:12,570 --> 00:02:13,560 children they have. 35 00:02:14,370 --> 00:02:15,220 That's fine. 36 00:02:15,240 --> 00:02:21,390 We can do two or somebody else has about not seven children. 37 00:02:21,390 --> 00:02:24,180 That's quite a few or zero children. 38 00:02:24,480 --> 00:02:25,680 That works great. 39 00:02:25,680 --> 00:02:32,580 But if I try and insert something much larger, a 200 children would get an error out of range value 40 00:02:32,580 --> 00:02:33,490 for that column. 41 00:02:33,510 --> 00:02:41,550 So if there is any possibility somebody could have more than 128 children or 147, then fine, maybe 42 00:02:41,550 --> 00:02:43,190 we use small int or medium int. 43 00:02:43,200 --> 00:02:48,630 This is all just about optimizing storage in the amount of space that each one of these values takes 44 00:02:48,630 --> 00:02:49,340 to store. 45 00:02:49,350 --> 00:02:50,970 So INT is a default. 46 00:02:50,970 --> 00:02:52,470 That's all we've been using. 47 00:02:52,470 --> 00:02:54,510 You can store quite large numbers. 48 00:02:54,510 --> 00:03:00,900 There is a larger, there's big int which stores way larger numbers but takes up double the space and 49 00:03:00,900 --> 00:03:02,760 then there's medium, small and tiny. 50 00:03:02,880 --> 00:03:07,740 So if you really care and you're trying to be, you know, trying to optimize storage, which is a good 51 00:03:07,740 --> 00:03:10,770 thing to do, I just feel like it's overkill when you're starting out. 52 00:03:10,770 --> 00:03:12,150 But it's good to know about. 53 00:03:12,150 --> 00:03:16,800 And if you're in a situation where you do care about it, then you can take a look at this table or 54 00:03:16,800 --> 00:03:20,550 go to the docs and find the appropriate sized integer. 55 00:03:20,790 --> 00:03:24,780 The last thing we'll talk about with ints is the signed versus unsigned. 56 00:03:24,780 --> 00:03:28,080 So by default, we're working with signed integers. 57 00:03:28,080 --> 00:03:35,040 When we say data type is int or tiny int, I can go from -128 up to 127. 58 00:03:35,040 --> 00:03:38,880 So technically I could have a negative number of children in here. 59 00:03:38,880 --> 00:03:41,310 Negative three maybe. 60 00:03:41,310 --> 00:03:42,360 I don't want that. 61 00:03:42,360 --> 00:03:46,470 So what I can do is say that we're only working with unsigned now. 62 00:03:46,470 --> 00:03:51,450 We're also going to learn how to add constraints checks to say that a number has to be greater than 63 00:03:51,450 --> 00:03:52,890 something or between something. 64 00:03:52,890 --> 00:03:59,670 So this is not the only way or the main way that you would go about enforcing a positive number of children. 65 00:03:59,670 --> 00:04:07,890 But it is a way of saying every tiny int in this table is going to be positive because it is a signed 66 00:04:07,890 --> 00:04:10,290 integer versus unsigned. 67 00:04:10,290 --> 00:04:18,209 So it looks like this when we create our table and we drop this table parent recreate it, and instead 68 00:04:18,209 --> 00:04:24,270 of simply saying children is of type tiny int I say tiny int unsigned. 69 00:04:24,890 --> 00:04:31,130 And it's going to look exactly the same if I try and insert a new child or a new parent in there with 70 00:04:31,130 --> 00:04:32,540 three children, it works. 71 00:04:32,540 --> 00:04:38,930 But if I try and do negative three, we're now out of range because we specified this has to be an unsigned 72 00:04:38,930 --> 00:04:45,890 tiny int, which just means there's no negative sign and that allows us to store a higher possible max. 73 00:04:45,890 --> 00:04:46,090 Right. 74 00:04:46,140 --> 00:04:52,940 155 But the minimum is now zero, so you can use unsigned as a keyword with any of these others you 75 00:04:52,940 --> 00:04:53,270 could do. 76 00:04:53,270 --> 00:04:55,790 INT unsigned big int unsigned. 77 00:04:55,910 --> 00:04:57,320 That's enough about integers. 78 00:04:57,320 --> 00:05:01,550 I usually just stick with int unless I know for sure I'm dealing with something small.