How to Create Table in PostgreSQL | Create Table, set Primary key & Auto-Increment in PostgreSQL DB

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back so guys in this video we are going to learn how to create a table inside post address SQL database okay so now guys let's get started so guys I have created One fun. DB database okay so inside this database we find a schemas over here so schemas is basically nothing but your database tables so guys let's uh click on this Arrow to open that nav bar and inside this we see a by default public folder okay so inside this public folder you should go and move to the tables so let's open this tables you see that it is empty right now so guys there are many ways to create the tables either you click on this public you just need to right click so just on Create and here you find that table and second way you can just go to your table structure here I mean inside your public folder just go on this table right click create and here is your table so both does the same thing let's click on this table and now guys First Step here you see you enter the name of the table so let us take an example of students so my table name is going to be students and owner live it by default and everything just live that and now guys let's go to the second tab over here which is about adding the column fields and now guys here you see a plus icon let's click on that and you can just start adding your column so guys First Column I will add it here and let's select the data type for this ID so so basically we are going to give a int that is integer let's select that and yep we want to make this as a primary key so let's just make it to true that means it is accepting primary key and also guys I want to set the auto increment by default so you can just click on this edit button okay so we are on the general tab let's move to this constraints so inside constraints we set up our autoincrement part so here you find the type constraint type I want to make it as identity so we are adding this and here you will find what type of identity is so here you have two options always and by default so guys there is a difference between these two things but does the job same so we are going to select always and just give one over here like we are going to start incrementing from one okay and you can just leave this blank it will fill automatically now guys you can close this again click on this same edit button so it minimizes and now guys let's add more few columns name and let's add a Vare I mean character so Vare comes in the mySQL database that is PHP my admin and here that means character varing so let's add this and you can give the length so I'll give 255 my max length that's it and now guys let's add more two columns which is course and here character wearing 255 and let's add the last column that is status which is going to be a Boolean type guys that is true or false so here you can take a small int which gives like true or false value okay and by default I want to make it zero if we insert the record we will submit as one and if you want to add some comments guys you can just click on this edit and here is a uh status that is name and here is a commment so 0 equal to inactive 1 equal to active Okay and now you can click back and let's save this table guys so let's click save perfect so here you see we have a students table created and if you go inside this you can find that columns so let's open that columns all that column fields are ready so now guys you can just uh if you want to see all the SQL queries you just need to select on each column names it just shows you what and all things are done inside this column field and if you want to see how much uh you have done the primary key foreign key setup you can just go to this constraint here let me just view this constraint and here you see that students primary key is set okay with this ID done guys so guys we have successfully created our table in our post address SQL so guys let us insert one data and see here and on this student let's right click and move to script so here is the script and just select with the insert script perfect okay so here it gives some formats so I'm not going to add this public just remove that and make it null give a space and let me align this and remove the ID guys because we have done the auto increment already and the value here the first value is ID so let's remove the name so here I'm going to give a single code add Fonda then next value the course in single codes U BCA and what will be the status let me make it to one which is active and now guys let's click on this play button to execute your query so let's click here you can see query returned successfully in 30 milliseconds so now guys we need to see whether this data is stored or not so you can just go back to again that students table right click on it go to script and here you see select script let's click on that it just opens in a new tab and here is your insert tab okay you can just switch and here you see guys we have a table let me remove this and just add a star select star from my students table let's execute this query by clicking on this play button here you see the record has been inserted perfect so now guys let's get back on the previous tab of insert query let me change the value like with prakash let's do it MCA and yep let's execute okay one more query inserted now get to our select query let's run again perfect so guys you see that we have a two records in our table so guys we have success y learned how to create a table inside our postgress database and also set up the primary key and also with the auto increment part and inserting the data too so guys in this video that's it thank you for watching this video please subscribe like and share
Info
Channel: Funda Of Web IT
Views: 4,533
Rating: undefined out of 5
Keywords: fundaofwebit, how to create table in postgresql, how to set primary key in postgresql, how to set auto increment in postgresql, Create Table, set Primary key & auto-increment in PostgreSQL, set primary key for id in postgresql pgadmin, set auto-increment key for id in postgresql pgadmin, postgresql database tutorial step by step, create database in postgresql, create database in postgres
Id: NhfeCY4FwGk
Channel Id: undefined
Length: 6min 46sec (406 seconds)
Published: Sun Oct 22 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.