1 00:00:00,090 --> 00:00:06,250 So the next couple of videos are all about tables, which are the most important part of SQL. 2 00:00:06,270 --> 00:00:09,090 They are the true heart of using SQL. 3 00:00:09,270 --> 00:00:14,580 And in this first video, we'll start off by setting the stage or setting the table, if you will. 4 00:00:14,580 --> 00:00:20,910 Let me get away with that for how they work, what they are, and then we'll dive into data types next, 5 00:00:20,910 --> 00:00:25,080 and then we'll actually create tables and see the code that you use to create them. 6 00:00:25,200 --> 00:00:26,520 So let's get started. 7 00:00:27,540 --> 00:00:33,510 The first thing you should know is that a database is just a bunch of tables, so we've already created 8 00:00:33,510 --> 00:00:36,360 a couple of empty databases and deleted them as well. 9 00:00:36,630 --> 00:00:39,570 But what goes in them are just a bunch of tables. 10 00:00:39,570 --> 00:00:41,340 That's where the data is stored. 11 00:00:41,940 --> 00:00:48,780 As a short aside, this is in a relational database, so everything we're talking about that uses SQL, 12 00:00:48,810 --> 00:00:55,980 things like my SQL PostgreSQL, those are relational databases, and they use tables, they use tabular 13 00:00:55,980 --> 00:01:01,140 data, but not every single database in the world does, and we'll see some examples of those later 14 00:01:01,140 --> 00:01:01,620 on. 15 00:01:01,830 --> 00:01:07,650 This course is not about those types of databases, but it helps to kind of bring them in to show you 16 00:01:07,650 --> 00:01:08,970 some contrast to what you're learning. 17 00:01:08,970 --> 00:01:10,230 So we'll see that later on. 18 00:01:10,710 --> 00:01:12,060 Just a short caveat there. 19 00:01:13,530 --> 00:01:14,900 So tables hold the data. 20 00:01:14,910 --> 00:01:16,260 That's my definition. 21 00:01:16,860 --> 00:01:20,130 If you want the boring Wikipedia definition, it looks like this. 22 00:01:20,460 --> 00:01:26,160 Tables are a collection of related data held in a structured format within a database. 23 00:01:26,190 --> 00:01:28,050 Hopefully you're still awake after that. 24 00:01:28,500 --> 00:01:32,250 But let's take a quick example using cats. 25 00:01:33,090 --> 00:01:36,690 So we're going to model some cats data using a table. 26 00:01:37,680 --> 00:01:40,500 So let's take a quick look at the cat's table. 27 00:01:40,710 --> 00:01:41,820 Drumroll, please. 28 00:01:42,330 --> 00:01:43,800 Dumped it or dumb? 29 00:01:44,850 --> 00:01:45,210 I know. 30 00:01:45,210 --> 00:01:46,530 It's pretty hilarious. 31 00:01:47,130 --> 00:01:48,690 You're probably falling out of your chair. 32 00:01:49,440 --> 00:01:55,020 All right, so the real cats table, at least in this context, doesn't have an apostrophe. 33 00:01:55,260 --> 00:01:56,640 Look, something like this. 34 00:01:56,640 --> 00:02:01,950 And of course, there's a million different ways we could break down the data for a cat from modeling 35 00:02:01,950 --> 00:02:02,510 cats. 36 00:02:02,520 --> 00:02:11,070 In my case, I just went with name, breed and age so we could do plenty of other things, like location, 37 00:02:11,070 --> 00:02:16,080 gender is spayed, is neutered, that sort of thing. 38 00:02:16,080 --> 00:02:18,210 But just doing name, breed and age. 39 00:02:19,590 --> 00:02:22,020 So I've put a couple of cats in here. 40 00:02:22,590 --> 00:02:25,620 We've got Blue, who's a Scottish foaled, who's one year old. 41 00:02:25,620 --> 00:02:26,550 That's my cat. 42 00:02:26,940 --> 00:02:32,790 We've got Rocket, who is a Persian, who is three years old, totally made up Monty, who's a tabby 43 00:02:32,820 --> 00:02:34,110 who is ten years old. 44 00:02:34,110 --> 00:02:36,120 That is my childhood cat. 45 00:02:36,510 --> 00:02:39,900 He's still kicking and biting people. 46 00:02:39,990 --> 00:02:42,720 We've got Sam, who is a munchkin. 47 00:02:42,720 --> 00:02:45,120 If you don't know what that breed is, look them up. 48 00:02:45,120 --> 00:02:47,340 They're pretty hilarious, although kind of sad. 49 00:02:47,340 --> 00:02:51,970 They have really stubby legs, who is five years old, also made that cat up. 50 00:02:51,990 --> 00:02:54,240 So some terminology. 51 00:02:54,840 --> 00:03:00,300 When we're talking about tables and you hear the term columns, it's referring to the headers on that 52 00:03:00,300 --> 00:03:00,870 table. 53 00:03:01,170 --> 00:03:06,210 So what are the different components of data, the different pieces that have to be there? 54 00:03:06,240 --> 00:03:09,150 In our case, we have name, breed and age. 55 00:03:09,750 --> 00:03:14,580 So those are the columns, and then the rows are the actual data in the table. 56 00:03:14,730 --> 00:03:16,830 So here's a row blue. 57 00:03:16,830 --> 00:03:19,920 The cat is one row, rocket is another row. 58 00:03:19,950 --> 00:03:21,600 Monty is another row. 59 00:03:21,600 --> 00:03:23,280 Sam is another row. 60 00:03:23,280 --> 00:03:28,530 I really wish that was lined up correctly, but I just drove myself nuts trying to get it to work. 61 00:03:28,530 --> 00:03:30,480 Please forgive me anyways. 62 00:03:30,480 --> 00:03:34,470 So databases are made up of lots and lots of these tables. 63 00:03:34,470 --> 00:03:36,390 It's usually not just one. 64 00:03:36,840 --> 00:03:42,780 If you have a really, really simple app and you're just storing one thing, then it will just be one. 65 00:03:42,780 --> 00:03:47,430 But usually apps are pretty complicated and data is complicated. 66 00:03:47,430 --> 00:03:49,170 All that we modeled there was cats. 67 00:03:49,170 --> 00:03:54,120 But imagine if this was actually an app, let's say it was a pet sitting app. 68 00:03:54,120 --> 00:03:56,910 And cats were one thing that we had to keep track of. 69 00:03:56,910 --> 00:04:03,780 But we also have to keep track of owners and the pet sitters and addresses and dates and appointments 70 00:04:03,780 --> 00:04:04,380 and payments. 71 00:04:04,380 --> 00:04:06,600 And those are all going to be tables. 72 00:04:06,600 --> 00:04:11,700 Some of them might even be multiple tables, but for now we're not going to really worry too much about 73 00:04:11,700 --> 00:04:12,060 that. 74 00:04:12,060 --> 00:04:15,000 But just to show you, sometimes it does get crazy. 75 00:04:16,000 --> 00:04:19,510 You can click this link or I'll click it, follow my own instructions. 76 00:04:19,959 --> 00:04:27,580 To see the breakdown of some of the tables that Facebook's database or a social network might use in 77 00:04:27,580 --> 00:04:28,390 their database. 78 00:04:28,390 --> 00:04:32,230 So this is not actual this is not 100% accurate. 79 00:04:32,230 --> 00:04:34,360 There are things that are missing or incomplete. 80 00:04:34,360 --> 00:04:39,550 But this just shows all the different tables, or at least some of the different tables involved in 81 00:04:39,550 --> 00:04:41,050 a pretty complex app. 82 00:04:41,050 --> 00:04:49,210 So as you can see, there is a bunch of them here, things like account and event and message and notification, 83 00:04:49,210 --> 00:04:54,820 website, screen, name, address, blah, blah, blah, all these different things to take into consideration 84 00:04:55,060 --> 00:04:56,650 so things can get messy. 85 00:04:56,650 --> 00:05:00,940 And as we progress in this course, you will start working with multiple tables. 86 00:05:00,940 --> 00:05:02,140 You'll see how they connect. 87 00:05:02,290 --> 00:05:06,970 But we haven't even seen how to create a single table yet, so we're going to focus just on individual 88 00:05:06,970 --> 00:05:09,220 tables and then we'll move on from there.