1 00:00:00,750 --> 00:00:01,320 All right. 2 00:00:01,430 --> 00:00:10,700 So let's create a table. If you remember to go to our Postgres database we simply write psql 3 00:00:10,700 --> 00:00:14,980 then our database name and we'll enter the database. 4 00:00:15,130 --> 00:00:18,410 And now we can communicate with it using SQL. 5 00:00:18,430 --> 00:00:19,950 Now let's create a table. 6 00:00:20,060 --> 00:00:21,060 How can we do that. 7 00:00:21,940 --> 00:00:29,380 Again SQL comes with some language. Language syntax that we can use. And to create a table we can 8 00:00:29,380 --> 00:00:30,840 use something like this. 9 00:00:30,970 --> 00:00:34,580 We say 'CREATE TABLE' which is an SQL command. 10 00:00:34,870 --> 00:00:43,780 We enter a table name followed by brackets and then we say what we want the column_1 to say with 11 00:00:43,780 --> 00:00:52,940 the data type, column_2 with the data type, column_3 with the data type and then ending it with semicolon. 12 00:00:52,940 --> 00:00:56,010 Let me just press enter and see what happens here. 13 00:00:56,180 --> 00:01:05,030 I get an error 'type "datatype" does not exist' and that is because datatype is referring to what Postgres 14 00:01:05,060 --> 00:01:12,000 or our relational database knows, we have to say ahead of time what type of data 15 00:01:12,020 --> 00:01:14,400 column_1, column_2, and column_3 hold. 16 00:01:15,590 --> 00:01:23,030 If we go back to our Chrome browser we see that for Postgres we have a few data types that we can 17 00:01:23,030 --> 00:01:29,240 hold. String datatypes, numeric datatypes, and date and time datatypes. 18 00:01:29,360 --> 00:01:33,180 And each one of them have different things. For a numeric data type 19 00:01:33,230 --> 00:01:37,900 We have integer which is a 4 byte integer. 20 00:01:38,000 --> 00:01:43,980 We have bigint which allows for a bigger number and all these different things, 21 00:01:44,000 --> 00:01:49,870 we have money which is currency value and the reason we have to give this datatype is because of the 22 00:01:49,880 --> 00:01:57,080 way databases work. They're optimized to make sure that as long as everything is the same in their column 23 00:01:57,410 --> 00:02:00,840 they're able to work really really fast to perform actions. 24 00:02:02,190 --> 00:02:10,550 In our case let's use some of the most common ones. We can use text for the first column. 25 00:02:10,620 --> 00:02:11,370 So let's do that. 26 00:02:11,370 --> 00:02:16,110 I'm going to press the up arrow and get create table. 27 00:02:16,110 --> 00:02:21,300 I'm also going to name this table, let's call it users 28 00:02:24,000 --> 00:02:39,550 and column_1 will be name, datatype can be text, column_2 we can say that is age and datatype for an 29 00:02:39,550 --> 00:02:40,390 age. 30 00:02:40,390 --> 00:02:43,870 Well if we look down here we look at numeric types. 31 00:02:43,960 --> 00:02:49,920 We want to use something like smallint which is a 2-byte signed integer. 32 00:02:50,080 --> 00:02:56,320 It means that a max for a smallint, if I go to smallint Max 33 00:02:58,990 --> 00:03:04,820 we see that the max range is 32,762. Well nobody's going to be that 34 00:03:04,820 --> 00:03:05,530 old, right? 35 00:03:05,530 --> 00:03:14,160 So we can use smallint for now lets do that. I'm going to say age is smallint. 36 00:03:14,300 --> 00:03:24,140 And finally the third column will just have 'birthday' and birthday can be a date datatype and we can 37 00:03:24,140 --> 00:03:32,460 just have date let's press enter and I get create table. 38 00:03:32,610 --> 00:03:37,670 Let's look at our PSequel here. And I'll minimize this. 39 00:03:37,900 --> 00:03:48,190 And if I click refresh here I see that we have users. Look at that and we have columns for the table users 40 00:03:48,220 --> 00:03:50,470 that is name, age, birthday. 41 00:03:50,520 --> 00:03:53,110 It tells us the type and the length. 42 00:03:53,110 --> 00:03:56,320 So now we have our table. Awesome. 43 00:03:56,560 --> 00:04:06,700 There's also a way to do it here if we do '\d' I get list of relations and look at that we 44 00:04:06,700 --> 00:04:13,600 have our users table and the owner which is me, very Cool. 45 00:04:13,600 --> 00:04:14,210 There you go. 46 00:04:14,290 --> 00:04:20,620 We've created our first table. Now that we have this we can start entering some information. 47 00:04:20,620 --> 00:04:24,800 And by the way you might be asking how many times do we run these commands. 48 00:04:25,090 --> 00:04:30,490 Well ideally once you create your database and it lives somewhere on a computer somewhere in the world 49 00:04:31,540 --> 00:04:33,740 you only run this once, right. 50 00:04:33,910 --> 00:04:40,420 You create a table of what you want your database to look like and the rest is just filling in and inserting 51 00:04:40,420 --> 00:04:43,180 information and reading information off of it. 52 00:04:43,180 --> 00:04:49,510 So this is the command that we're going to set up when we create our own database to set up our schemas. 53 00:04:49,510 --> 00:04:52,470 And then after that it'll just run on its own. 54 00:04:52,660 --> 00:04:55,530 And It will be able to communicate with the back end. 55 00:04:55,720 --> 00:04:57,370 It's going to be very fun. 56 00:04:57,370 --> 00:05:00,560 By the way before we get into the next video I want to show you one more command. 57 00:05:00,580 --> 00:05:03,980 We learned the '\d' shows us our tables. 58 00:05:04,060 --> 00:05:12,480 If I do '\q' We exit out of here and we're back to the terminal. 59 00:05:12,490 --> 00:05:14,470 All right I'll see you in the next one. 60 00:05:14,860 --> 00:05:15,100 Bye-bye.