I will call you back again for another video lecture in PostgreSQL.
And in this video lecture we go ahead and learn how to create a table in PostgreSQL.
Alright, so in the previous lecture I was able to teach you how to create a database, and I was able
to teach you how to drop a database and also taught you how to connect to your database.
Now let's go ahead and learn how to create a table inside our database.
So we are going to have a quick assignment before this.
So it just depends on you.
And that is washing over this.
You can see I have uh some of the database here.
I have a Postgres and school.
I have dropped the student database and I created a new database called school.
So you can inaugurate a new database of any name of your choice, or you go ahead and use the student
database, or you go ahead and drop the student database and create a database called school.
Then we are going to use the student's name as a symbol inside the school.
Because students have to be inside the school.
So that is a quick assignment for you to walk ahead and drop the student's database and create a school
database.
And then we join me while we create the student table inside the school database.
How?
Right now you can see that everything is still about Postgres.
And then I have to first of all connect to the SQL database.
And for me to do that, go ahead and put the backward slash C or connect and then school and hit enter.
And now you are now connected to the database school as user Postgres.
Well the next thing is you can see that everything right in here is actually looking so so so confusing
because we have so many things in here.
Now I just want us to use those school database I just entered, and for that I have to play everything
I have here.
So in order to play everything on this SQL show or you need to do is backward slash that exclamation
mark, then C, r, s and hit enter.
And now I'm dealing with just the SQL database.
So inside this code base I will go ahead and create a table.
And to create a table I need to do is I'll go ahead and say create table.
And then I'm going to give the table name.
Let me say is students.
So the table name is going to be student.
And then I'll go ahead and uh open up this.
And then I'm going to add in the student, uh, ID the student first name the student last name the
GP.
And in row means date, the date the student enrolled.
Go ahead and click enter.
I can actually continue this in one single line.
What if you hit enter?
It's not going to close because you've not put a semicolon at the end.
So whenever you put a semicolon at the end of this, that is when this database has been finished and
you move to the next lane.
What?
As follows.
I have not put a semicolon at the end.
I could actually go ahead and hit enter and keep moving while creating this table.
Now the very first one is the students underscore ID right.
So strings underscore id and the data type is going to be integer rank with a comma.
Now you can go over to PostgreSQL documentation.
And under chapter we have on the chapter eight the data types.
You can go ahead and see some of the data types.
We have the integer because I used integer just now.
And most of us will be like what is int?
So int is a force sign byte integer and that is the int.
And now we're also going to use something like character.
And now we have a fixed length character.
We're not going to use that for single one.
We're going to use variable length character for the string.
So I'm going to always use varchar for names and text.
And I'm going to use int for numbers.
And I'm going to use decimal.
I'm going to use that, uh, for the decimal numbers and for floats you can also use for floats, but
for integer decimal our range is a decimal.
Right.
So now I'll go ahead and minimize this.
Let's go back to the table.
And now I've added the students ID.
What I need again is the first name and the last name.
Go ahead and see first okay.
This is going to be all lowercase first underscore name.
And just like I told you the data type is going to be var because that is the variable length we are
going to use.
And then I'm going to make that to be like 50 characters and put a comma.
And the next one is going to be the last underscore name.
And the data type is going to be varchar.
And the character is going to be like 50 and click comma.
And the next one is the GP.
And GP is going to be a decimal because it's going to be like 3.5, 4.7 and so on, and it's going to
be just one decimal place.
So I'll go ahead and say, um, this is going to be decimal, and then this is going to be one and then
by one decimal place and then go ahead and put a comma.
Then we'll go ahead and add the enroll dates.
Right.
So this is going to be the in row underscore date.
Then I went ahead and close this and then put a semicolon at the end.
And now that I've added a semicolon I've come to the final end.
And if I should go ahead and hit on enter you can see that my table is now created.
So if you want to see the table you've just created, just go ahead and put backward slash D and hit
enter.
And you can see I have uh under my schema I have public uh students table for uh Postgres.
And if I should go over to Pgadmin, let's go ahead and, uh, refresh this.
Go ahead and refresh and then go under table under school and then move under tables.
You can see I have students right in here.
So a table called students has been created under here.
And remanding this under the SQL show.
All right.
Now if you want to select the that's for you to see whatever you created the column names you want to
check the columns under the school table.
All I need to do is I'll go right in here and I'm going to say backward slash D.
And then the table name is A students.
And I'm going to hit enter.
And you can see I have a students ID integer first name and character varying and last name character
varying.
And GP is a numeric.
And one by one the error dates is date.
Now let's go over here and we can go under this place and take on query two.
And there we click on query two.
We can actually create these I can go ahead and say uh select uh all.
And then from.
Students.
So select all from students.
Put a semicolon at the end of this and hit enter.
Now you go ahead and run.
This so is the cutest query.
And uh you can see under here I have a students ID, first name, last name, GPA and enroll date.
Okay, uh, whatever I have on that SQL show, if I get over to Pgadmin, I can actually do that.
All right, so our application will boot up.
Then whatever I will do here, I'll go over to Pgadmin and I'm going to show you that.
So go ahead and practice with this.
And if you have any questions please go ahead and use the question and answer section.
And I'm going to get back to you as soon as possible.
Thank you so much.
And I'm going to see you in the next video lecture.