WEBVTT

1
00:00:00.120 --> 00:00:01.350
<v ->Hi guys and welcome back.</v>

2
00:00:01.350 --> 00:00:03.780
In this video we're going to show you how to delete

3
00:00:03.780 --> 00:00:07.540
entire tables using the drop table command.

4
00:00:07.540 --> 00:00:08.460
It's pretty straight forward,

5
00:00:08.460 --> 00:00:10.480
all we have to do is say drop table

6
00:00:10.480 --> 00:00:12.440
and then the table we want to drop.

7
00:00:12.440 --> 00:00:14.680 line:15% 
The first part tells the database that we want to

8
00:00:14.680 --> 00:00:17.610 line:15% 
delete the table as if it never existed

9
00:00:17.610 --> 00:00:19.040
and the second one is just a table

10
00:00:19.040 --> 00:00:20.910
that we want to delete.

11
00:00:20.910 --> 00:00:22.320
And that's really it.

12
00:00:22.320 --> 00:00:25.530 line:15% 
We can add an if exists clause in there

13
00:00:25.530 --> 00:00:26.960 line:15% 
to prevent a database error

14
00:00:26.960 --> 00:00:29.250 line:15% 
if the database doesn't already exist.

15
00:00:29.250 --> 00:00:31.753 line:15% 
For example, if we were to execute the command twice

16
00:00:31.753 --> 00:00:34.140 line:15% 
you need this in order to prevent that error

17
00:00:34.140 --> 00:00:35.810 line:15% 
the second time.

18
00:00:35.810 --> 00:00:37.970 line:15% 
Let's go into the SQLite viewer

19
00:00:37.970 --> 00:00:40.470 line:15% 
and have a look at how we can code this ourselves.

20
00:00:41.960 --> 00:00:44.160
All right we're here in DB Browser

21
00:00:44.160 --> 00:00:45.580
and I just wanted to show you how you can

22
00:00:45.580 --> 00:00:47.730
delete tables in here.

23
00:00:47.730 --> 00:00:49.550
First of all, if you go to database structure

24
00:00:49.550 --> 00:00:51.700
you can just select the table and click this

25
00:00:51.700 --> 00:00:52.930
delete table button.

26
00:00:52.930 --> 00:00:54.100
That's the easiest way.

27
00:00:54.100 --> 00:00:57.490
You can right click and delete a table like that

28
00:00:57.490 --> 00:01:01.840
or you can of course go into the execute sequel tab

29
00:01:01.840 --> 00:01:05.190
and type drop table users.

30
00:01:05.190 --> 00:01:07.980
Then running that will get rid of the table completely.

31
00:01:07.980 --> 00:01:09.610
Now of course if you run this again,

32
00:01:09.610 --> 00:01:11.900
you're gonna get an error because it doesn't exist

33
00:01:11.900 --> 00:01:16.900
so, like similar to create table we can do if exists.

34
00:01:17.350 --> 00:01:20.510
Remember with create table we used if not exists

35
00:01:20.510 --> 00:01:23.130
because we want to create it and here we need to use

36
00:01:23.130 --> 00:01:26.310
if exists because we're trying to delete it if it is there

37
00:01:26.310 --> 00:01:28.450
and so running this now gives us no error

38
00:01:28.450 --> 00:01:31.160
because it only runs the drop table

39
00:01:31.160 --> 00:01:32.563
if it already exists.

40
00:01:33.470 --> 00:01:34.990
All right, hope this has been useful.

41
00:01:34.990 --> 00:01:36.110
Thank you for joining me.

42
00:01:36.110 --> 00:01:37.833
I'll see you in the next video.

