WEBVTT

00:07.940 --> 00:11.630
Okay, so in the previous lecture we dropped a primary key.

00:11.630 --> 00:14.000
And now we want to add a primary key back.

00:14.000 --> 00:17.510
Because if you go under student ID the bit ends.

00:17.540 --> 00:21.890
There is nothing like a P key which is the primary key.

00:21.920 --> 00:23.390
We have dropped it.

00:23.420 --> 00:28.640
Now if I should go ahead and add this primary key, I'm going to get an error.

00:28.640 --> 00:32.990
If I should go straight and do that from back, then go ahead and show you how to add a permanent key.

00:33.020 --> 00:36.440
And we want to see other table.

00:36.920 --> 00:40.820
And I want to alter either the students table.

00:42.200 --> 00:43.820
So alter table students.

00:43.850 --> 00:49.190
Then go ahead and add the primary key.

00:49.670 --> 00:50.090
All right.

00:50.120 --> 01:00.830
Now I'm going to add that to students underscore ID you can actually add this primary key to any of

01:00.830 --> 01:04.720
these columns so we can add to multiple columns for Y.

01:04.750 --> 01:13.990
I just want these to be here is because I just want that to just be for the stress ID.

01:14.200 --> 01:21.940
You can add that to maybe email or you add that to first name, last name, or because people are going

01:21.940 --> 01:25.120
to have exactly the same first name or last name.

01:25.150 --> 01:29.170
Yes, some two or more pieces can have exactly the same first name and last name.

01:29.170 --> 01:32.710
It happens, but they can't have the same email address.

01:33.430 --> 01:34.090
Yes.

01:34.090 --> 01:40.000
So it can also add email address to also be a primary key.

01:40.420 --> 01:42.430
But there's a problem right in here.

01:42.460 --> 01:50.530
If I should go ahead and uh, actually put a semicolon at the end of this and try to create this primary

01:50.560 --> 01:52.570
key, I'm going to run into a problem.

01:52.570 --> 01:53.020
Let me go ahead.

01:53.020 --> 02:01.570
I show you that it says the stress ID is duplicate could not create a unique index stress ID because

02:01.570 --> 02:02.180
Perimeter.

02:02.180 --> 02:09.290
We have the two people still there and that is don't go ahead and check them out.

02:10.730 --> 02:13.880
If we go ahead and check out these, we still have these two guys here.

02:13.910 --> 02:19.430
So first of all we need to delete these two people from here so we can be able to add our primary key.

02:19.430 --> 02:26.390
And to do that we go ahead and use the delete key word from the students table.

02:26.960 --> 02:30.320
So delete from students.

02:30.890 --> 02:36.500
Uh we have the ID or we are the students.

02:36.530 --> 02:39.830
Underscore ID is equal to one.

02:39.830 --> 02:44.390
And put a semicolon at the end of it and underscore here and is equal to square.

02:44.390 --> 02:45.020
And check it out.

02:45.050 --> 02:49.880
So we deleted two of them and they are gone right now.

02:49.910 --> 02:58.730
I can also go ahead and then put back our primary key a warhead and the other the table.

03:00.830 --> 03:08.320
So alter table and the table is a day student so terrible.

03:08.320 --> 03:12.130
Students are ahead and are at the.

03:13.120 --> 03:14.260
Primary key.

03:15.370 --> 03:16.990
So at primary key.

03:16.990 --> 03:20.680
And now we're going to add that primary key to.

03:21.400 --> 03:27.280
The students underscore ID the input is semicolon at the end of it.

03:27.670 --> 03:30.700
Now we can go ahead and execute this query and check it out.

03:30.700 --> 03:32.590
So our table.

03:32.620 --> 03:44.080
Now if I should go ahead and uh select all from students and put a semicolon at the end.

03:44.260 --> 03:45.640
Let's go ahead and check it out.

03:45.640 --> 03:48.610
So you can see that the primary key is back.

03:49.060 --> 03:52.510
And we have deleted one of these, uh, students.

03:52.510 --> 03:57.340
And our table is now 999 out of 999.

03:57.460 --> 04:02.470
Let's go ahead and, uh, add back the student.

04:02.650 --> 04:06.000
Let's go ahead and put in this back again.

04:06.000 --> 04:10.650
So this is what we copied from the coach studio.

04:10.680 --> 04:12.990
Uh, studio code, which will have right in here.

04:12.990 --> 04:15.000
So I'm going to put this back again.

04:15.000 --> 04:23.490
But, uh, right now we go ahead and, uh, set this, go ahead and, uh, execute this query.

04:23.520 --> 04:24.360
Let's check it out.

04:24.360 --> 04:30.660
So I've inserted it and then I can go ahead and uh select all.

04:33.690 --> 04:35.910
Select all from.

04:43.050 --> 04:49.530
So go ahead and select all from students and put a semicolon at the end.

04:49.530 --> 04:51.630
And let's go ahead and run this and check it out.

04:51.630 --> 04:54.540
So now we have added this as a last one.

04:54.540 --> 04:59.460
And uh over here you can see we now have 1000 rows.

04:59.460 --> 05:08.800
And uh the stress ID is not One for Marco and Love, and we just have one of each right in here.

05:08.800 --> 05:12.550
So it is no longer duplicates because the primary key is back.

05:12.580 --> 05:13.420
That is it.

05:13.420 --> 05:21.400
So we have seen that we can be able to remove, and it can also add the primary key back to any of that

05:21.400 --> 05:22.060
column.

05:22.240 --> 05:28.360
Now the students or the first name, the last name, the email, the gender, the row, date or column.

05:28.360 --> 05:31.300
So you choose one of these and add your primary key to it.

05:31.300 --> 05:34.780
So your primary key, your primary key is going to always be your neck.

05:34.780 --> 05:40.330
So you add that to either one of them, either the student's ID, the first name, last name, or the

05:40.330 --> 05:43.750
email address, or the gender, or the date or the country.

05:43.750 --> 05:46.810
So you choose one of them and add your primary key to that.

05:46.810 --> 05:48.310
So that is it for now.

05:48.310 --> 05:51.490
And if you have any questions, use the question and answer section.

05:51.490 --> 05:54.190
And I'm going to get back to you as soon as possible.

05:54.220 --> 05:55.180
Thank you so much.

05:55.180 --> 05:58.390
And I'm going to see you in the next video lecture.
