WEBVTT

1
00:00:00.290 --> 00:00:01.620
<v Jose>Hi guys and welcome back.</v>

2
00:00:01.620 --> 00:00:03.070
In this video we're going to learn

3
00:00:03.070 --> 00:00:05.990
how to delete rows from a database

4
00:00:05.990 --> 00:00:08.860
and we're also going to implement this in our app.

5
00:00:08.860 --> 00:00:11.010
So Delete From looks like this,

6
00:00:11.010 --> 00:00:15.520
we've got "Delete from users where surname equal Smith."

7
00:00:15.520 --> 00:00:17.150
So the first part tells the database

8
00:00:17.150 --> 00:00:19.940
that we want to delete rows from the user's table,

9
00:00:19.940 --> 00:00:22.540
by default that's going to delete everything.

10
00:00:22.540 --> 00:00:25.020
So this second part here, the Where clause,

11
00:00:25.020 --> 00:00:27.710
filters them so that we only delete

12
00:00:27.710 --> 00:00:30.250
the rows that match this clause.

13
00:00:30.250 --> 00:00:31.790
Otherwise it's going to delete everything.

14
00:00:31.790 --> 00:00:33.400
Seriously important.

15
00:00:33.400 --> 00:00:36.800
Remember the Where clause, just as we did with the update,

16
00:00:36.800 --> 00:00:38.760
otherwise everything's going to be deleted,

17
00:00:38.760 --> 00:00:41.350
and you'll get to keep the table but none of the contents.

18
00:00:41.350 --> 00:00:42.940
So that's pretty important.

19
00:00:42.940 --> 00:00:44.410
Don't forget about that.

20
00:00:44.410 --> 00:00:46.440
Let's go into our code editor

21
00:00:46.440 --> 00:00:49.373
and work on deleting rows from our table.

22
00:00:50.540 --> 00:00:53.350
All right, so what we're going to do is create our Query,

23
00:00:53.350 --> 00:00:55.690
that takes care of deleting movies.

24
00:00:55.690 --> 00:00:57.967
And as you know, it's really straight forward,

25
00:00:57.967 --> 00:01:02.967
"Delete movie" for example can be " Delete from movies".

26
00:01:03.130 --> 00:01:04.390
And here we're telling SQL

27
00:01:04.390 --> 00:01:07.384
that we want to delete something from the movies table.

28
00:01:07.384 --> 00:01:11.770
And we wanna do "Where title equal question mark"

29
00:01:11.770 --> 00:01:13.390
and that means that in the function

30
00:01:13.390 --> 00:01:16.730
we are going to pass in the argument with the titles

31
00:01:16.730 --> 00:01:19.320
that we want to delete from the table.

32
00:01:19.320 --> 00:01:22.810
We're going to be re-implementing this file for stage two

33
00:01:22.810 --> 00:01:24.550
in the next video but I wanted to show you

34
00:01:24.550 --> 00:01:27.270
how this works in DB Browser as well,

35
00:01:27.270 --> 00:01:29.410
so let's go over to that.

36
00:01:29.410 --> 00:01:31.050
So here I've opened DB Browser.

37
00:01:31.050 --> 00:01:32.500
If I go to Browse Data,

38
00:01:32.500 --> 00:01:35.500
you can see that I've got "The Matrix" here.

39
00:01:35.500 --> 00:01:37.820
And if we go to the Execute SQL tab,

40
00:01:37.820 --> 00:01:40.744
we can do "Delete from movies".

41
00:01:40.744 --> 00:01:42.430
Remember if we just run this,

42
00:01:42.430 --> 00:01:45.020
that's gonna delete everything from the movie's table.

43
00:01:45.020 --> 00:01:47.224
At the moment we only have one row so it's not a big deal

44
00:01:47.224 --> 00:01:50.810
but we always want to include a Where clause.

45
00:01:50.810 --> 00:01:54.130
So we'll do "Delete from movies where title equal"

46
00:01:54.130 --> 00:01:56.970
And now we pass in the string inside quotation marks,

47
00:01:56.970 --> 00:02:00.230
single quotation marks, and that's "The Matrix"

48
00:02:00.230 --> 00:02:02.660
And now we can run this,

49
00:02:02.660 --> 00:02:05.300
and you can see that get "Query executed successfully."

50
00:02:05.300 --> 00:02:07.624
We go back to Browse Data, the movie's gone.

51
00:02:07.624 --> 00:02:09.515
All right, thank you guys for watching this video.

52
00:02:09.515 --> 00:02:11.480
We're going to go into the next one

53
00:02:11.480 --> 00:02:13.822
and re-implement the database.py file.

54
00:02:13.822 --> 00:02:15.053
I'll see you there.

