1 00:00:00,180 --> 00:00:02,050 So now we move on to tables. 2 00:00:02,070 --> 00:00:04,500 This is the real heart of SQL. 3 00:00:04,530 --> 00:00:06,510 Yes, we make a new database. 4 00:00:06,510 --> 00:00:08,730 We use a database that's important to know. 5 00:00:08,730 --> 00:00:14,400 But like I said previously, we do that occasionally, but then we constantly work with tables and the 6 00:00:14,400 --> 00:00:17,340 data inside of tables within a given database. 7 00:00:17,340 --> 00:00:21,870 So we have this empty shell of a database or maybe multiple empty shells of databases. 8 00:00:21,870 --> 00:00:23,010 They have nothing in them. 9 00:00:23,010 --> 00:00:27,630 Tables are what we need to put in those databases so that we can hold data. 10 00:00:28,110 --> 00:00:30,240 So you may have heard the term table before. 11 00:00:30,360 --> 00:00:33,210 A database is really just a bunch of tables. 12 00:00:33,210 --> 00:00:36,930 Now, when I say database, that only applies to a relational database. 13 00:00:36,930 --> 00:00:40,890 If we're talking about something like MongoDB, that's not a relational database. 14 00:00:40,890 --> 00:00:47,460 So it doesn't use tables, but all the SQL flavored database variance, they all consist of a bunch 15 00:00:47,460 --> 00:00:50,850 of tables and tables are what hold our data. 16 00:00:50,850 --> 00:00:57,960 They describe the format and the shape of our data, and then they hold collections of data that follows 17 00:00:57,960 --> 00:00:58,650 that shape. 18 00:00:58,650 --> 00:01:04,769 So a more technical definition would be a table is a collection of related data held in a structured 19 00:01:04,769 --> 00:01:06,270 format within a database. 20 00:01:06,270 --> 00:01:08,820 Now that structured part is very important. 21 00:01:09,000 --> 00:01:12,600 Also, the fact that it's a collection of data is very important. 22 00:01:13,020 --> 00:01:16,350 So let's say that we were working with cats data. 23 00:01:16,350 --> 00:01:20,520 We're building a pet shelter or a vet database or something. 24 00:01:20,520 --> 00:01:23,280 This would be one way to structure my information. 25 00:01:23,280 --> 00:01:26,340 I could say this is what a cat looks like in our database. 26 00:01:26,340 --> 00:01:28,350 This is the cat's table. 27 00:01:28,680 --> 00:01:30,270 Every cat has a name. 28 00:01:30,270 --> 00:01:33,420 Every cat has a breed, every cat has an age. 29 00:01:33,420 --> 00:01:35,400 I'm defining the structure. 30 00:01:35,400 --> 00:01:38,700 That's the first part of a table, and it will start empty. 31 00:01:38,700 --> 00:01:39,960 This one is not empty. 32 00:01:39,960 --> 00:01:44,340 And then we insert data into the table following that structure. 33 00:01:44,340 --> 00:01:48,540 So every cat has a name, a breed, and an age. 34 00:01:48,720 --> 00:01:55,230 So some basic terminology we call the headings or the headers of each table columns. 35 00:01:55,230 --> 00:01:57,120 So this table has three columns. 36 00:01:57,120 --> 00:02:00,660 Now I'm visualizing it here right as an actual table. 37 00:02:00,690 --> 00:02:02,430 It's not stored this way. 38 00:02:02,640 --> 00:02:09,479 It's stored as some compressed thing that looks nothing like human readable code, but it will be displayed 39 00:02:09,479 --> 00:02:12,690 to me nicely in the same way that we see this right here. 40 00:02:12,690 --> 00:02:13,260 Print it out. 41 00:02:13,560 --> 00:02:14,790 It looks like a table. 42 00:02:14,790 --> 00:02:18,810 But again, this is just a slide diagram that I'm drawing for you. 43 00:02:18,810 --> 00:02:21,030 This has nothing to do with SQL on its own. 44 00:02:21,330 --> 00:02:25,590 Okay, so we have our columns name, breed and age, and then we have the rows. 45 00:02:25,590 --> 00:02:28,890 Those are the actual entries, the actual data in the table. 46 00:02:29,070 --> 00:02:30,570 So we have one row here. 47 00:02:30,600 --> 00:02:32,220 Blue is a Scottish fold. 48 00:02:32,220 --> 00:02:33,270 She's one year old. 49 00:02:33,720 --> 00:02:37,320 We have Rocket who's a Persian cat, three years old and so on. 50 00:02:37,320 --> 00:02:40,950 These are all rows, their entries into this table. 51 00:02:40,950 --> 00:02:44,700 But the first step is to get this table empty. 52 00:02:44,700 --> 00:02:47,490 But with a structure we're telling SQL. 53 00:02:47,490 --> 00:02:48,900 Okay, here's our cat's table. 54 00:02:48,900 --> 00:02:54,330 It has these three different columns, the three pieces, and then once that's done, we can insert 55 00:02:54,330 --> 00:02:55,200 data in. 56 00:02:55,920 --> 00:03:00,330 So databases in general consist of lots of tables. 57 00:03:00,330 --> 00:03:06,420 Well, I say that referring to a large application or even just a basic application you might work with. 58 00:03:06,450 --> 00:03:11,340 There's going to be lots of different entities and almost every entity will have its own table. 59 00:03:11,730 --> 00:03:17,130 So there might be a user's table, a friend's table, a photos table. 60 00:03:17,130 --> 00:03:23,010 If we are making some sort of Instagram clone or something, a comment table and all sorts of stuff 61 00:03:23,010 --> 00:03:28,650 for advertising and for tracking users and user behavior, you could have hundreds of different tables 62 00:03:28,650 --> 00:03:30,510 so it can get a little crazy. 63 00:03:30,510 --> 00:03:32,700 Here are some simple ish examples. 64 00:03:32,700 --> 00:03:38,910 This is some of the tables that exist in the Wikipedia SQL database. 65 00:03:38,910 --> 00:03:40,530 Now, this is coming from Wikipedia. 66 00:03:40,620 --> 00:03:44,790 It could be out of date, but we'll see things like a user. 67 00:03:44,790 --> 00:03:50,250 Every user has a name and a password and an email and a whole bunch of other things. 68 00:03:50,250 --> 00:03:53,410 But then we have pages, Wikipedia pages, right? 69 00:03:53,520 --> 00:03:57,690 And Wikipedia revisions because people can revise pages. 70 00:03:58,110 --> 00:04:06,090 There's different sites, there's logs that are written images and files and all sorts of other things. 71 00:04:06,090 --> 00:04:13,260 We don't have to worry about tags, lots of information here that is stored all in separate tables. 72 00:04:13,260 --> 00:04:18,480 Now, of course, most of these tables are connected or related in some ways, like pages and users 73 00:04:18,480 --> 00:04:19,950 or revisions and users. 74 00:04:19,950 --> 00:04:21,329 Who's making the revision? 75 00:04:21,329 --> 00:04:26,130 Well, some user is so there's some connection, but we're not worrying about that just yet. 76 00:04:26,130 --> 00:04:27,210 Here's another example. 77 00:04:27,210 --> 00:04:35,460 This is an old very out of date attempt at modeling the table structure of a website like Facebook. 78 00:04:35,460 --> 00:04:40,380 We have things like basic information for a user sex. 79 00:04:40,380 --> 00:04:43,200 If they're interested in men and women, you can tell this is out of date. 80 00:04:43,200 --> 00:04:45,600 I guess that they even break it down that way. 81 00:04:45,600 --> 00:04:48,060 Looking for friendship, relationship. 82 00:04:48,060 --> 00:04:48,360 All right. 83 00:04:48,360 --> 00:04:50,370 Basic information, contact information. 84 00:04:50,370 --> 00:04:56,280 But then we have things like a profile, an account, a credit card, different events. 85 00:04:56,280 --> 00:04:57,660 We have photos. 86 00:04:57,660 --> 00:04:59,190 All these different entities are. 87 00:04:59,460 --> 00:05:03,660 Senate with their own tables and again, lots of lines connecting them together. 88 00:05:03,750 --> 00:05:05,200 So we are not starting there. 89 00:05:05,220 --> 00:05:10,770 We're starting with good old cats, three columns, a couple of rows, but we have to learn how to make 90 00:05:10,770 --> 00:05:11,370 a table. 91 00:05:11,370 --> 00:05:16,530 And before we can create a table, we have to talk about data and the different types, the different 92 00:05:16,530 --> 00:05:18,330 categories of data we can work with.