1 00:00:00,060 --> 00:00:05,010 So to close out this section here, we're going to get a little practice with data types and the syntax 2 00:00:05,010 --> 00:00:06,970 for creating and deleting tables. 3 00:00:06,990 --> 00:00:08,400 So one more activity. 4 00:00:08,760 --> 00:00:16,050 This time I'd like you to imagine that you work at a pastry shop, so you're going to manage and I manage 5 00:00:16,050 --> 00:00:21,120 in air quotes that you can't see me doing right now, but you're going to manage a pastry shop in the 6 00:00:21,120 --> 00:00:22,680 inventory for these pastries. 7 00:00:22,680 --> 00:00:28,110 It's going to be very simplistic, but you'll need to create a pastries table and there should be at 8 00:00:28,110 --> 00:00:29,010 least two columns. 9 00:00:29,010 --> 00:00:30,540 If you want to add more, that's fine. 10 00:00:30,630 --> 00:00:32,520 But a name for the pastry. 11 00:00:32,520 --> 00:00:33,810 So what is it? 12 00:00:33,810 --> 00:00:42,480 A croissant, a chocolate donut, whatever it is, as well as a quantity, which would be a number. 13 00:00:42,480 --> 00:00:48,450 So I could go in and see that there are ten croissants or five chocolate crescents and so on, but we 14 00:00:48,450 --> 00:00:50,880 won't fill it with data because we haven't seen it to do that. 15 00:00:50,880 --> 00:00:53,760 So we're just defining the table in the columns. 16 00:00:54,150 --> 00:00:55,530 So I'd like you to do that. 17 00:00:56,010 --> 00:01:03,180 Then use a command to inspect your table and the columns using the MySQL command line interface. 18 00:01:03,180 --> 00:01:08,760 So one of those short little commands we saw just to make sure, basically to check your work and then 19 00:01:08,760 --> 00:01:11,880 lastly delete all that hard work, delete your table. 20 00:01:12,240 --> 00:01:18,900 So pause the video if you'd like, go through this and come back when you're done and I'll be here. 21 00:01:21,000 --> 00:01:22,710 So I'm back in cloud nine. 22 00:01:22,980 --> 00:01:29,700 I'm actually still if I select database, I'm still using Cat app. 23 00:01:29,970 --> 00:01:34,440 There are no tables in it right now because I deleted the cat's table, but I'm just going to put our 24 00:01:34,440 --> 00:01:39,480 pastries table in here, even though it has nothing to do with Cat app, maybe it's a cat bakery or 25 00:01:39,480 --> 00:01:40,140 something. 26 00:01:40,320 --> 00:01:42,750 I've seen dog bakery, so maybe we're not too far off. 27 00:01:42,750 --> 00:01:45,210 But anyways, it's just a silly exercise. 28 00:01:45,630 --> 00:01:54,510 So we want to create a table, so create a table and then the name of the table will be pastries, plural, 29 00:01:55,770 --> 00:01:57,300 then in parentheses. 30 00:01:57,540 --> 00:02:01,440 And I'm going to do it on one line just to show you that it's not a problem. 31 00:02:01,950 --> 00:02:04,110 So we'll have the name of the pastry. 32 00:02:05,040 --> 00:02:11,370 And one thing that you may be tempted to do if you come from some other databases is to put a column 33 00:02:11,370 --> 00:02:11,790 there. 34 00:02:12,090 --> 00:02:17,700 That's something I find myself doing, just some from experience that I have some other tools, but 35 00:02:17,700 --> 00:02:18,780 you don't want that there. 36 00:02:18,780 --> 00:02:23,670 So if you see me doing that, hopefully I catch myself to create table pastries. 37 00:02:23,700 --> 00:02:29,730 Name is going to be a var char and it should be 50 characters maximum. 38 00:02:30,420 --> 00:02:31,950 So in parentheses 50. 39 00:02:32,280 --> 00:02:33,900 And then we have age. 40 00:02:34,050 --> 00:02:36,240 Excuse me, we have quantity. 41 00:02:36,240 --> 00:02:41,820 And if you wanted to abbreviate that with just Q t y, which is what you'll see pretty commonly, you 42 00:02:41,820 --> 00:02:42,780 could do that as well. 43 00:02:42,900 --> 00:02:44,430 And that's just an integer. 44 00:02:45,330 --> 00:02:47,940 Then we need our semicolon to end it. 45 00:02:48,300 --> 00:02:51,930 We hit enter and we have a nice little error message. 46 00:02:51,930 --> 00:02:54,210 So that was accidental. 47 00:02:54,210 --> 00:02:58,560 I'm not going to try and play it off like it did it on purpose, but I am going to leave it in here 48 00:02:58,920 --> 00:03:02,850 and that's mainly because it's something that pops up pretty commonly. 49 00:03:03,480 --> 00:03:06,690 People aren't perfect, at least I'm not, especially when I'm recording. 50 00:03:06,990 --> 00:03:08,580 Got a lot of stuff to worry about. 51 00:03:09,360 --> 00:03:11,850 Can you identify what went wrong? 52 00:03:13,080 --> 00:03:13,650 To give you a hint. 53 00:03:13,650 --> 00:03:14,970 I'm just missing one character. 54 00:03:16,480 --> 00:03:16,960 Yup. 55 00:03:16,960 --> 00:03:17,680 If you got it. 56 00:03:17,680 --> 00:03:23,770 I'm missing a comma here, and the error messages aren't always that useful, but it tells me there's 57 00:03:23,770 --> 00:03:25,180 an error in my syntax. 58 00:03:25,970 --> 00:03:27,950 And it's something near quantity. 59 00:03:28,150 --> 00:03:36,770 INT So right before that, I'm missing a comma and it's treating all of this as name, which is wrong. 60 00:03:36,770 --> 00:03:40,010 We need that comma there so we can recall the line. 61 00:03:40,970 --> 00:03:41,810 Go back. 62 00:03:42,870 --> 00:03:44,460 And insert our comma. 63 00:03:45,390 --> 00:03:51,270 Now when we do it, we get Query OC and we'll move on to the next part, which was to make sure things 64 00:03:51,270 --> 00:03:57,180 worked so we could either do show tables and then we can do show. 65 00:03:57,330 --> 00:03:58,740 Let's do describe. 66 00:03:59,010 --> 00:04:01,470 Describe pastries. 67 00:04:03,500 --> 00:04:09,890 Perfect name var quantity is an int and the last thing was to drop our pastries. 68 00:04:09,890 --> 00:04:12,620 Table drop table. 69 00:04:13,040 --> 00:04:13,970 Pastries. 70 00:04:14,330 --> 00:04:15,530 Goodbye pastries. 71 00:04:16,860 --> 00:04:18,260 And just to verify it worked. 72 00:04:18,269 --> 00:04:21,480 Let's do show tables again and there's nothing here. 73 00:04:21,750 --> 00:04:22,520 Perfect. 74 00:04:22,530 --> 00:04:26,340 So the next section is all going to be about inserting data. 75 00:04:26,340 --> 00:04:27,390 We make tables. 76 00:04:27,390 --> 00:04:28,110 They're empty. 77 00:04:28,140 --> 00:04:29,430 How do we get stuff in there?