WEBVTT

00:00.290 --> 00:06.060
OK so we've made it through the C R and you portions of crud.

00:06.060 --> 00:11.430
Now we finally made it to D which stands for delete or destroyed depending on who you ask.

00:11.430 --> 00:17.970
So in this video we're going to see how to do things in my ask you will well and it's pretty straightforward.

00:17.970 --> 00:24.330
It's very similar to selecting things except rather than just selecting something you're going to delete.

00:24.330 --> 00:26.260
So let me show you what I mean.

00:27.030 --> 00:32.970
Here's an example that will delete any cat with the name eg in our database.

00:32.970 --> 00:40.110
So imagine first of all that we were selecting all we would have is select from cats where name is equal

00:40.110 --> 00:41.010
to egg.

00:41.400 --> 00:48.650
So if we ran that it would give us the cat or cats with name egg and we can swap out select with delete.

00:48.830 --> 00:49.950
And that will delete it.

00:49.950 --> 00:56.400
So that same rule of thumb from before where I said Make sure you update something that your selection

00:56.460 --> 00:57.270
is correct.

00:57.360 --> 01:01.500
Then do the update because it will I mean there's no undo button unfortunately.

01:01.560 --> 01:07.190
Same holds true and more so with delete because your data is gone as soon as you delete it.

01:07.200 --> 01:08.660
So let's try this will delete.

01:08.700 --> 01:09.490
Eg.

01:10.120 --> 01:10.910
Let's do.

01:10.920 --> 01:13.550
First of all it's like start from cats.

01:13.620 --> 01:16.060
Just make sure we have egg in here.

01:16.080 --> 01:17.610
There he or she is.

01:17.610 --> 01:21.840
I'm not quite sure what I was intending with that name.

01:21.840 --> 01:22.350
Eg.

01:22.410 --> 01:27.360
So what we'll do first is just make sure we can select appropriately before we delete.

01:27.770 --> 01:34.740
So select star from cats where name equals eg.

01:34.890 --> 01:37.760
Remember that this is case insensitive.

01:38.010 --> 01:38.940
Just for now.

01:39.330 --> 01:41.200
I'll do lowercase just to prove that.

01:41.280 --> 01:43.200
All right so we get egg perfect.

01:43.530 --> 01:52.100
So now to remove egg delete from and then we can just copy this.

01:52.310 --> 01:58.670
So before I hit enter I do need to take a moment to address something pretty serious and that is that

01:58.670 --> 02:02.330
no cats are being harmed no cats are dying here.

02:02.630 --> 02:08.290
Yes they're being deleted from this table but in reality deletion doesn't mean death.

02:08.390 --> 02:10.630
It means that they're being adopted.

02:10.640 --> 02:15.710
Perhaps to a loving family that will treat them with the care that they deserve.

02:15.950 --> 02:21.360
So there's no death here and I hope I don't receive any Furius comments about how I'm treating animals

02:21.360 --> 02:21.860
in my course.

02:21.860 --> 02:23.030
I love animals.

02:23.090 --> 02:24.950
I learned from my first course.

02:24.950 --> 02:25.930
I made a mistake.

02:26.180 --> 02:31.320
I will never refer to deleting dogs or cats as killing them.

02:31.780 --> 02:33.250
I'm very sorry for that.

02:33.740 --> 02:36.050
So again these cats are not dying.

02:36.050 --> 02:38.480
So with that out of the way let's hit Enter

02:41.740 --> 02:52.210
now let's go back and select star from cats and as he can see eg is now gone.

02:52.210 --> 02:54.850
Also something that does come up sometimes.

02:54.880 --> 02:58.030
Notice that the cat ID's have not shifted.

02:58.030 --> 02:59.160
They're still the same.

02:59.170 --> 03:04.750
Some of my students in the past have had the expectation that the IDs would alter but they always will

03:04.750 --> 03:05.610
stay the same.

03:05.920 --> 03:12.240
And that's because when something is inserted into a table that unique ID is generated for it remembers

03:12.250 --> 03:18.700
the primary key and eventually will learn about having multiple tables that interact with one another

03:18.970 --> 03:22.460
and will be storing these ideas in other tables.

03:22.780 --> 03:28.470
So if it changed that could be problematic because we'd have to change it in multiple places anyways.

03:28.620 --> 03:33.830
I'm trying to say is that we removed 4 but we still have 5 6 and 7.

03:33.850 --> 03:36.910
This didn't change to 4 and change to 5 and so on.

03:36.910 --> 03:39.440
All right so we deleted that rest in.

03:39.490 --> 03:43.280
I mean enjoy your new life with your happy family eg.

03:43.690 --> 03:48.780
So one last thing here is that if you look at what I've written here delete from Cats.

03:49.060 --> 03:50.330
What do you think that will do now.

03:50.330 --> 03:53.270
I don't run it but what do you think this would do.

03:54.280 --> 03:56.790
And the answer is that it deletes everything.

03:56.980 --> 03:58.390
All cats.

03:58.580 --> 04:00.740
They're all released to their happy families.

04:01.330 --> 04:04.500
So that's important to know that you can do that.

04:04.690 --> 04:09.580
So it's different than dropping a table because dropping a table gets rid of the table entirely and

04:09.580 --> 04:15.190
all data inside of it but deleting from cats just deletes the entries in the cat's table.

04:15.190 --> 04:16.570
But we still have the shell.

04:16.570 --> 04:18.070
We still have the cats table.

04:18.340 --> 04:21.240
There shouldn't be very many times when you need to use this command.

04:21.640 --> 04:26.500
I'm not going to do it just yet because I want us to have our cat's data for a little bit for the next

04:26.530 --> 04:31.730
exercises but just keep that in mind because we didn't specify a WHERE clause over here.

04:32.890 --> 04:35.200
It's the same as selecting without a WHERE clause.

04:35.200 --> 04:37.770
It's like everything so this will delete everything.

04:38.160 --> 04:40.900
OK next up you're going to practice deleting.
