#7 Introduction to PostgreSQL: Creating a New Table
Sign in to perform actions on this cast!
Hello everyone welcome back. And today we will be learning how to create a new table in our database. So let's get started right away. So let's go pee SQL postgres. So for those people who haven't seen earlier videos we currently have a user contest one. And when you want to log into a specific user can you have the type E. SQL postgres dash Uber users. And test one the user name. So now we have entered I want to connect to the database. So in order to connect to the database we type backslash C. And the database name. I think our database name was database privilege from our last video. So that is the name. So I'll tell you you're connected to the database if it's if that database exists and then now we want to display table. So backslash beeping for display tables. And obviously we haven't created any tables yet in our previous videos so we cannot create one. So in order to create a table we simply type create table and table name here. So I'm gonna name my table name pets because I'm gonna create a table of pets. Remember that? This is not case sensitive but it is a good practice to write an uppercase because that's just a syntax for um SQL query. You have an open bracket. You can type all of these in the same line but I prefer to type it in the different lines so it's easier to see. So you can type I. D. Serial primary key not known in the same line and then the next column or you can spread it out like me I prefer to type in multiple lines. So this will execute until you type the semi colon. So it's safe to just press enter and type serial primary key. No so you don't have to include them not know what not notices when you insert your values. It cannot be known. So this I. D. Must have a number and what serial primary key is it automatically whenever you create inserted value, it will automatically create an I. D. For you. That's why you include serial primary key. So I'm just gonna write it this for simple purpose we will have our name of pet. Um for me we're gonna write for car 50. So that means for our name it's gonna be a string and it's gonna hold 50 letters maximum. So if you have a really really long pet name and you would want a longer string then make a tie for a car to 50 or whatever number you wish for. But I think 50 is enough for us. We're also gonna have aged. So whatever the pet's name age so we have to note what it is. So in this case age is gonna be integer. And then now um I guess three things is enough for now. So I'm gonna close the bracket. Type the semicolon. So once I press enter this whole query I mean or this whole line will execute because there's a semi colon they will know when to stop. So as you can see I was able to create a table. So let's press D. T. Again. And now you can see that I have a table named pets. And it's an owner text one because I was a um owner that were logged into right now. So if we want to see what is inside this pets table we would have to um do some queries. But as you know we haven't insert any values into it yet. So in the next video we'll learn to insert some values into this pets table. Mm.