1
00:00:00,180 --> 00:00:02,130
Now this video is going to be a slight departure.

2
00:00:02,250 --> 00:00:08,430
We're still working with inserting data, but it's a slight side note, which has to do with something

3
00:00:08,430 --> 00:00:09,750
called warnings.

4
00:00:10,530 --> 00:00:16,860
So to illustrate what I'm describing here, if we tried to insert something that looks like this, so

5
00:00:16,860 --> 00:00:20,280
we're going back to cats and our cats have a name and an age.

6
00:00:21,060 --> 00:00:26,700
If we tried to insert a cat whose name is this gigantic string, this is a cat named Charlie, which

7
00:00:26,700 --> 00:00:27,540
is also a human name.

8
00:00:27,550 --> 00:00:32,790
In fact, I know a couple of Charlie's fun facts if we're trying to put that as this cat's name.

9
00:00:32,880 --> 00:00:34,110
An age is just ten.

10
00:00:34,950 --> 00:00:39,750
If we do that, let's go ahead and copy this just so I don't have to type that.

11
00:00:40,740 --> 00:00:42,660
Make sure we have our cat's table.

12
00:00:43,140 --> 00:00:45,210
Let's do describe cats.

13
00:00:46,170 --> 00:00:47,250
So name and age.

14
00:00:47,430 --> 00:00:50,220
Remember, there's this restriction here of 50.

15
00:00:51,720 --> 00:00:54,060
I'm just going to paste that and put a semicolon.

16
00:00:56,340 --> 00:01:01,770
I get something that says Query Oak, one row affected, one warning.

17
00:01:03,180 --> 00:01:08,250
Just to double down on that, I pulled it out into a separate slide one morning.

18
00:01:08,460 --> 00:01:09,180
Oh, my gosh.

19
00:01:09,180 --> 00:01:10,230
What's going on?

20
00:01:10,560 --> 00:01:17,490
Well, if we wanted to know what that warning was, we can use this command show warnings.

21
00:01:18,120 --> 00:01:22,440
So we'll go back and type show warnings.

22
00:01:23,760 --> 00:01:27,570
And I want you to pause and think, what is the warning?

23
00:01:27,960 --> 00:01:31,680
If you were to guess, obviously, we haven't talked about it yet, but what do you think?

24
00:01:31,680 --> 00:01:32,430
I'll see.

25
00:01:34,170 --> 00:01:39,090
And the answer is, I get a warning here that says data truncated for column name.

26
00:01:39,870 --> 00:01:45,120
So that corresponds to name here, which had a limit of 50 characters.

27
00:01:45,120 --> 00:01:47,310
And this is more than 50 characters.

28
00:01:47,310 --> 00:01:50,010
I can't remember how much it is, but it's more than 50.

29
00:01:50,760 --> 00:01:53,640
And if we look at cats.

30
00:01:58,280 --> 00:02:05,780
You'll see that our first of all, our table gets a little messed up here, but the string for name

31
00:02:06,020 --> 00:02:09,440
gets cut off after this cat is named Charlie, which is also a.

32
00:02:10,060 --> 00:02:11,730
And then the rest is gone.

33
00:02:11,740 --> 00:02:17,410
So it's not like it's hidden and it's not displaying, it's just not stored at all.

34
00:02:17,620 --> 00:02:18,970
So that's important to note.

35
00:02:19,240 --> 00:02:21,640
So that's one warning that we saw there.

36
00:02:22,210 --> 00:02:24,610
And that happened when our data was truncated.

37
00:02:25,150 --> 00:02:28,950
Can you think of another warning we could generate deliberately?

38
00:02:28,960 --> 00:02:31,690
What's something we could do that would give us a warning?

39
00:02:32,320 --> 00:02:38,560
So pause the video or don't, but try and come up with something based off of what we have currently

40
00:02:38,560 --> 00:02:39,790
set up for cats.

41
00:02:40,270 --> 00:02:43,450
How could we insert something that would give us a warning?

42
00:02:43,930 --> 00:02:49,750
All right, so what I was imagining is that we could try to insert something where we mixed up a data

43
00:02:49,750 --> 00:02:50,260
type.

44
00:02:50,260 --> 00:02:58,180
So let's say age instead of being an integer, we passed in some text random gibberish that should generate

45
00:02:58,180 --> 00:02:58,840
a warning.

46
00:02:58,840 --> 00:03:00,130
So let's try it now.

47
00:03:00,520 --> 00:03:02,710
Insert into cats.

48
00:03:03,670 --> 00:03:05,680
We'll do name first and then age

49
00:03:08,140 --> 00:03:12,820
and name will just be Lima.

50
00:03:12,820 --> 00:03:13,540
Why not?

51
00:03:13,750 --> 00:03:19,060
But age will be gibberish like that, which is not a valid integer value.

52
00:03:19,450 --> 00:03:26,020
We'll hit enter, we get one morning and we can view that warning with show warnings.

53
00:03:28,540 --> 00:03:30,550
And this time it's a different warning.

54
00:03:30,880 --> 00:03:32,850
It says incorrect integer value.

55
00:03:32,860 --> 00:03:36,540
So the last one we saw said that name was truncated.

56
00:03:36,550 --> 00:03:37,570
It was too long.

57
00:03:37,660 --> 00:03:42,700
This one is telling us that incorrect integer value for column age.

58
00:03:43,630 --> 00:03:46,030
So then here's a second thing for you to think about.

59
00:03:46,030 --> 00:03:52,540
And you probably I mean, you'll just have to guess, but what do you think is stored inside of H.

60
00:03:53,680 --> 00:03:54,700
Any ideas?

61
00:03:55,120 --> 00:04:05,270
Well, if we do a select star from Cat, we can see we have Lima whose age is zero.

62
00:04:05,290 --> 00:04:11,560
So in this case, if we screw something up, if we pass in some invalid data or a string instead of

63
00:04:11,560 --> 00:04:15,400
number, it will automatically set age to be zero.

64
00:04:15,760 --> 00:04:19,660
In a little bit, we'll see ways of changing that of changing that default.

65
00:04:19,899 --> 00:04:21,730
But for now, it's zero.

66
00:04:22,690 --> 00:04:24,990
Okay, so that's it for warnings at this point.

67
00:04:25,000 --> 00:04:30,970
Just be aware that if you do see one warning or two warnings or however many warnings after a query

68
00:04:31,360 --> 00:04:33,910
type show warnings and you'll be able to see your answer.

69
00:04:34,060 --> 00:04:39,790
However, I actually forgot to mention this if we do something invalid, so let's do the same thing.

70
00:04:40,180 --> 00:04:45,220
But instead of Lima, I'll call the cat Cusco.

71
00:04:46,270 --> 00:04:47,890
I can't remember if there's a Z in that.

72
00:04:49,990 --> 00:04:50,860
I don't know.

73
00:04:52,320 --> 00:04:52,450
Okay.

74
00:04:52,770 --> 00:04:59,640
Well, well, assume that there is so Cousteau with this crazy, crazy gibberish should give us a warning.

75
00:04:59,820 --> 00:05:07,620
But if I do something in between, like select star from Cats and now I do show warnings.

76
00:05:08,820 --> 00:05:09,600
Nothing.

77
00:05:09,690 --> 00:05:14,760
Our warning set is empty, so this is just something to be aware of.

78
00:05:15,210 --> 00:05:23,130
With that said, when you're creating applications using my SQL, that application, whatever you're

79
00:05:23,130 --> 00:05:29,340
using, let's say we're using JavaScript or Ruby that will have ways of handling these warnings and

80
00:05:29,340 --> 00:05:30,060
letting you know.

81
00:05:30,060 --> 00:05:33,870
But when you're working in the shell like this, you have to use the show warnings command.

82
00:05:33,900 --> 00:05:34,470
All right.

83
00:05:34,470 --> 00:05:35,820
That's all there is to warnings.

