1 00:00:00,240 --> 00:00:05,790 So now that we've learned how tables work and we've seen a little bit about data types, we finally 2 00:00:05,790 --> 00:00:07,470 get to start creating tables. 3 00:00:07,890 --> 00:00:12,930 So here is the magic syntax for creating a new table in my SQL. 4 00:00:12,960 --> 00:00:14,910 Here is the generic version. 5 00:00:15,060 --> 00:00:19,030 So it's create table and then the name of the table. 6 00:00:19,050 --> 00:00:23,790 So cats or users or people or results or whatever it is. 7 00:00:23,790 --> 00:00:25,380 And then in parentheses. 8 00:00:26,470 --> 00:00:30,280 A column name and then a space and the data type. 9 00:00:30,280 --> 00:00:34,750 And there are a few other things that can come along with the data type, but for now we're just talking 10 00:00:34,750 --> 00:00:35,580 about data type. 11 00:00:35,590 --> 00:00:39,670 So a column name like age is an INT. 12 00:00:40,540 --> 00:00:45,130 Or address is a var cha or var kah however you want to pronounce it. 13 00:00:45,880 --> 00:00:47,140 So that's the main idea. 14 00:00:47,380 --> 00:00:50,650 And you keep listing these columns as many as you need. 15 00:00:50,650 --> 00:00:52,600 It could just be one, it could be 20. 16 00:00:52,600 --> 00:00:55,720 And you separate them by columns, excuse me, by commas. 17 00:00:55,720 --> 00:00:59,620 And then when you finish, you add your semicolon, and that's that. 18 00:01:00,220 --> 00:01:06,130 Now you don't have to format it this way on separate lines, but I think it's easiest to understand. 19 00:01:06,190 --> 00:01:11,380 It's definitely easier to read when you get much more complex ones, but you could do it all in a single 20 00:01:11,380 --> 00:01:13,720 line, just like anything else in my SQL. 21 00:01:14,320 --> 00:01:17,620 So here's an actual example using our cat's table. 22 00:01:17,800 --> 00:01:20,110 So we're just working with name and age. 23 00:01:20,530 --> 00:01:22,360 Create table cats. 24 00:01:23,140 --> 00:01:28,690 One thing I should point out is that table names should be plural sized, so it doesn't actually matter 25 00:01:28,690 --> 00:01:30,940 for the mechanics or behind the scenes. 26 00:01:30,940 --> 00:01:31,780 It won't change anything. 27 00:01:31,780 --> 00:01:37,960 But you want to just follow this convention use plural, because that's what a table describes as multiple 28 00:01:37,960 --> 00:01:38,680 cats. 29 00:01:38,680 --> 00:01:40,690 Or people instead of person. 30 00:01:41,140 --> 00:01:42,400 Or payment instead of payment. 31 00:01:42,400 --> 00:01:43,150 And so on. 32 00:01:44,410 --> 00:01:49,660 So we have parentheses, and then we list our columns and their corresponding data types. 33 00:01:49,660 --> 00:01:54,760 So name will be a var char with a 100 character limit. 34 00:01:55,060 --> 00:01:58,390 Comma age will be an integer. 35 00:01:58,750 --> 00:02:01,630 So let's hop over to cloud nine and see if it works. 36 00:02:02,200 --> 00:02:05,040 So the first thing I'll do is just make a new database. 37 00:02:05,050 --> 00:02:10,060 You don't have to do this if you're following along, but I'll just call one cat app. 38 00:02:12,290 --> 00:02:12,580 Oops. 39 00:02:12,590 --> 00:02:13,670 Forgot my semicolon. 40 00:02:14,240 --> 00:02:16,190 Then we will use. 41 00:02:19,850 --> 00:02:20,400 Okay. 42 00:02:20,780 --> 00:02:25,520 So now the next thing we'll do is create table cat. 43 00:02:26,920 --> 00:02:29,110 And then we can either do parentheses here. 44 00:02:29,980 --> 00:02:35,350 And that's what I usually do when I'm working in the MySQL command line or in the shell. 45 00:02:36,160 --> 00:02:38,170 So you don't have to worry about spaces too much. 46 00:02:38,170 --> 00:02:51,010 So create table cats and then we'll say name is a var char 100 comma age is an int and then we'll close 47 00:02:51,010 --> 00:02:52,720 our parentheses with the semicolon. 48 00:02:53,610 --> 00:02:56,340 Query OC the zero rows affected. 49 00:02:56,610 --> 00:02:57,360 Perfect. 50 00:02:57,900 --> 00:02:59,220 It appears to have worked. 51 00:02:59,220 --> 00:03:00,750 Or at least we have to trust that it works. 52 00:03:00,750 --> 00:03:03,060 Because right now we don't have a way of testing that. 53 00:03:03,390 --> 00:03:06,330 But we will in the next video cliffhanger.