All right.
So let's go ahead and look at primary keys in PostgreSQL.
So in PostgreSQL we have this uh data set we inserted.
And if we go over and check out the students let's go ahead and say students and hit enter.
We have these students PK.
And that is the primary key.
So we can see we have this primary key and that is the students ID.
And over here you can see the stress ID pk the bigint is a primary key.
And uh we want to learn more about this primary key.
Now this primary key helps us to be able to restrict to datas with same information.
So nobody in this place, we have the same primary key of like one and N1.
Let me go ahead and show this.
This is what we have in the previous lecture and this is what we inserted.
And we have this guy right in here.
And this is a very fast one.
And it has the name Mark on and the ID is one.
Let's go ahead and check it out.
So the ID of this guy is one.
Now you can see it has a primary key of one uh ID one that is stress ID and the stress ID two.
Now we can have the same person having the same primary key.
Like this guy here.
It is not possible at all.
If we go ahead and try that, we're going to run into an error.
Let's go ahead and open up the Visual Studio.
And I'm going to say I want to insert into this.
Let me go ahead and say insert into students and I'm going to add a student.
That is a stress underscore ID.
and now if I go over here and add this ID one here and try to copy this, let me go ahead and copy this
and insert that.
I want to insert this.
And now I copied this.
And I'm going to minimize this right in here.
If I go over to this place and I try to insert that into the students table, I'm going to get an error.
So go ahead and clear this and I'm going to press what I just copied right in here.
And then go ahead and reduce this value so I can be able to see it.
All right.
So insert into students.
And now with our students ID then first name last name email gender error date country and values is
equal to one.
Now let's go ahead and execute this query.
Let's check it out.
Now you can see you have an error.
And what this error said is duplicate key value varies unique constraint.
Students peak t.
So that is the student ID.
It's also said here that our a stress ID equal to one already exists.
That's duplicate key value.
Whereas the unique constituents which is the primary key.
Now you can see that we have a very big problem because I'm not a not a problem at all.
So this helps us to actually make sure I would not have these two, uh data bit inserted.
And in that case it's going to give us a very big issue, because in a case where two persons have the
same ID, we are going to always run into problem.
So if you want to actually do that, all you need to do is you have to go ahead and, uh, drop the
primary key if you want to insert this.
And if I want to drop the primary key or I need to do is to go ahead and drop this constraint, call
the answer key.
Go ahead I see it.
So I'm going to start by deleting everything I have right in here.
And then I'll go ahead and use a keyword called quarter.
And then I'm going to alter the turbo and the turbo.
I want to alter is this to stable students.
And then I'll go ahead and drop using drop keyword.
And what I'm going to drop is this constraint.
All right.
Because you can see unique constraint.
So why I say constraints.
And now what is the name of the constraint that is to name the key.
So I'll go ahead and say the students uh underscore p key and put a semicolon at the end.
Now if I have this I'll go ahead and this to this and check it out.
Our table query returned successfully.
And you can see that now if I go ahead and delete everything I have here and, uh, paste back what
I just copied from Visual Studio and execute this query, we can see insights are zero.
One means return successfully.
And if I should go ahead and delete everything here and I'm going to say select all from students,
I put a semicolon at the end and the score had I checked out.
And now if you go down let's go ahead and move down.
Down here you can see we have our this has moved over to 1001.
And last we can see Mark con is equal to this.
And if we go ahead and select that from here I can go ahead and say select from students.
Where I'm going to say we are students.
Underscore ID is equal to one.
And if I should go ahead and run this, we can see we have Mark home.
And it appears twice.
So but this is not really very nice because you're not supposed to have this right.
So I hope that is very cool.
So this is the importance of the ID that is the primary key.
This is important.
The primary key in query or in PostgreSQL.
It helps you to avoid having two data and conflicting data, because there is no how you can know who
is Marco.
Right in here.
And who has this or who is this?
Because everything is just the same and you don't want to run into that problem.
So we have the first name, the last name, the same email address, same gender, uh, enrolled date
and from the same country.
And now you have a very big problem.
And if you have different stress ID, you can actually use that to separate them and know who is who.
And that would have been better.
So let's go ahead and put this done.
Practice with it.
And in the next video lecture we'll go ahead and put this back again and have a primary key right in
here because that is very, very, very important.
Thank you.
And I'm going to see you in the next video lecture.