All right.
So let's go ahead and look at the check constraint in PostgreSQL.
So the check constraint helps us to be able to determine the values we add into a column.
All right.
We have this gender.
And we remember we generated this.
It was auto generated for us not just by us.
And here we can see we have things like a female we have big or by gender.
And we have a full agenda.
We have non-binary and we have gender cue and so many more.
Now what I need to do is let's go ahead and check how many of these genders we have.
What I need to do is to go in and say, select a distinct and the distinct keyword we have asked to
actually differentiate the genders we have so select distinct gender from.
Students because we didn't generate this by ourself.
And then go ahead and execute this.
And you can see we have about eight different genders.
So I'm going to delete whatever it is.
Not either male or female.
We are going to be left with either male or female.
You can have bigender genderfluid or non-binary only gender and so on.
I don't know if this is actually the same with you, but this is what I have when I uploaded this and
it doesn't suppose to be so.
And you have to restrain people from entry, just only either male or female.
So I'm going to use this check constraint to actually do this.
So we go ahead and uh delete the following.
That is our gender Q and so on.
So I'll go ahead and uh, I'm going to skip this b roll so that I can always use this to see what genders
that are left.
So while I say delete key word and uh from students.
Where gender.
Is equal to.
So I'm going to copy the very first one here that is uh, go ahead and copy this.
And I'm going to press that here and put a semicolon at the end and execute this query.
Now I have removed the very first one.
So I'm going to copy the second one.
And I'm going to replace that.
And that is that.
And I'm going to copy non-binary.
And then I'm going to put that and delete it.
So the reason why I left it select distinct is to always see what them is.
All right.
So go ahead and copy this and go ahead and paste this here and execute the query.
and I'm going to copy this agenda and I'm going to press that.
Execute the query.
And I remain gender fluid.
I'm going to also delete that.
All right.
So I'm now left with a female and male.
So for us to be sure let's go ahead and uh also select everything.
Go ahead and select uh all from students.
I put a semicolon at the end and go ahead and check it out.
So we're now left with 898 out of 898.
Therefore, we have eliminated every order once and under the gender.
We are now left with, uh, male and female.
But what happens is that if we go over to Visual Studio.
So one can actually go ahead and copy this.
Let's go ahead and copy this and then go back in here.
And I'm going to put this down so that it's going to always show.
And, uh, the value here can be anything.
Instead of no a computer only.
Okay.
Let me see.
Fully male.
And if I go ahead and, uh, run this okay, I'm going to change the email because I've already made
this email to be unique constraint.
So I had to change this email.
And I'm going to say that this email is a digestive at businesswire.com.
I'll go ahead and execute this query.
Now get down here.
And down here you can see that, uh, the gender still email.
And if we go over and check this out go ahead and check this out.
Go ahead and delete everything here.
And it's the cutest query.
You can see that, uh, Palermo is still there because we just added that now, and I don't want anybody
to enter anything that is not male and female.
Go ahead and put this.
I'll go ahead and delete this.
So go ahead and execute this query.
And now we're now left with our male and female only.
So if we go back to select uh let's go ahead and uh.
Select all from.
Students.
And there is a query.
If you drag this down we have deleted that which is sorted and is no longer there.
Now let's go ahead and use a check constraint to prevent people from entering any number.
That's any gender that is not male or female.
And if I want to do that I'll go ahead and see other table.
And the table name is uh, students.
And then I'll go ahead and add a.
constraint.
And now I can give my constraint any name, or at least leave it so that PostgreSQL will give it a name.
All right.
So I'll go ahead and say add a.
Constraint.
And I can say that is a.
Students underscore gender.
So that is the name I give it.
And then I say check this.
And there we see gender.
Is equal to.
Mu or gender.
Is equal to.
Female.
So you are in a male or female.
So go ahead and drag this down.
So other students have constraints and are required and I see strength on the agenda, that is the name
of the constraint.
And that can also bring down these say check gender equal to male or gender equal to female, or put
a semicolon at the end of days.
Now we can go ahead and execute this query and our table or task successfully.
Now I'll go ahead and now select all.
From students up to semicolon.
And now this is our table.
Now let me go ahead and move over to Visual Studio.
And I'm going to copy this again.
Going to copy this one more time.
Let's try to add that.
And down here I'm going to press that.
And now remember we just copied what we just inserted previously.
And we have deleted it.
Now.
Want to retry it again and execute this query and says email.
Already exist.
And uh okay.
So we have ordered this email previously.
So the email constraint is what prevents that.
And now I'll go ahead and uh change the email just like we did.
And that is a gist of now I'll go ahead and add it to be fully email.
All right.
So good.
We have done a we have done the email constraint.
And uh, we added a unique constraint to our email.
So we're not able to add it.
But now we have changed the email.
And now we change the gender to pull email.
And now execute this query and check it out.
So it says error offering contains these check constraints.
Uh students gender.
So you can see that the students gender.
It says new row for racial students violates check constraints students gender.
And if I go ahead and, uh, open up our SQL show course head and uh, of course d students and hit
enter, we have a check constraint.
Status.
Gender.
And the check is equal to gender.
Equal to male.
Or gender equal to female.
So you can no longer add anything that is not either male or female.
Now go ahead and remove the pulley.
And I'm going to be left with male and female is to Steve at Businesswire.com.
And go ahead and try to add it.
Now that we have male as the gender and let's check it out.
So we have been able to add it and let's drag this down.
And down here you can see George, Steve G, Steve Dahl Businesswire.com and male.
So you can no longer add anything that is not male or female.
And that is very very beautiful.
Well go ahead and check it out.
Try it out and uh, try to implement that and have a force out table to accept only either male or female
gender.
That is so beautiful.
So I'm going to see you in the next video.
Thank you and see you then.