All right.
So in the previous lecture we are able to look at days.
Now I want to introduce you to something very important.
And do not just actually very important but very necessary.
See I have this right in here.
And if I should go ahead and insert this again, I'm going to get an error over here and check it out.
So there is an error.
Right now the error says already exists.
That is the email address.
And what if I go ahead and add in.
Let me say students underscore ID and then I go right over here and uh add the maybe that is 1006.
I think that is the what we have there.
And if we go ahead and run this check it out.
So it says select ID 1006 already exists.
Duplicate a key and it violates the unique constraints student's key and the previous one is the key,
that is for the email.
If we remove this and check the email is correct and check it out and this student's email key.
All right.
Now there is no problem.
I want us to actually not display this error anymore.
So we're going to use what is called on conflict.
Do nothing.
Yes.
On conflict do nothing.
If I want to do that like this.
First name them say students underscore ID.
And if I go ahead and put in the ID 1006 which has already existed, all I need to do is go back over
here, remove this, and I can continue on that same line.
That is why I remove that quotation mark, the semicolon at the end.
So the reason why I remove the semicolon at the end is to continue from the same line.
All I need to do is to go ahead and say on conflict, okay, notice on conflicts are okay.
So on Conflict.
Then I'll go ahead and pass in.
If that is for the stress ID, I'm going to say students underscore ID all right.
And then I'll go ahead and say do nothing.
So whenever there is a conflict just do nothing.
All right.
And it's quite an easy query now nothing actually happened.
And that nothing was actually added the Squire and check it out.
Done here would not have any similar, uh, ID right in here.
We just have only 100.
That means nothing actually happened and no error was shown.
All right.
And, uh, if we go over here and also check it out, if we go ahead and say we want to select everything
here and do the same, that means it will still work out fine.
So copy this and then let's go over to SQL.
And you can actually go ahead and paste this.
And then go ahead and hit enter.
And you can see inside there is that inside there there is no error.
But if there is no no conflict, do not.
Then you're going to see an error down here okay.
Now you can also do that for email.
Just go ahead and remove this for students.
I'll go ahead and remove the stress ID and the let's go ahead and run this again.
We have that's why less distress email because we have a unique constraint for the email.
So I'll just go right inside here.
And I'm going to pass in the word I say email and run this and check it out.
Nothing actually happened okay.
So you can see what happens on the email.
But if you go ahead and use something like first name or last name or the gender, because the gender
is just a check constraint is not a unique constraint or a primary key.
So the enroll date and country, if you try to put a maybe first name, let's go ahead and say we have
a first underscore name.
And if you run this you're going to get an error because it says there is no unique or exclusion constraint
matching on conflict specification.
So the on conflict specification.
First name is not going to work.
And let's go ahead and check with gender.
And let's go ahead and run this and check it out.
It says there is no unique or exclusion constraint matching on conflict specification.
So if you run this many times you can see that gender is not part of the constraint are talking about.
So the check constraint is not included but the unique constraint and the primary key is included.
So if you go ahead and uh add the unique constraint uh email and uh students ID is going to work out
fine.
So the no conflicts do nothing actually helps us to keep moving without throwing an exception or an
error right in here.
I hope that is cool.
So go ahead and practice with it.
And if you have any questions, 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.