Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
In this video we'll see how to delete all data from a table.
SQL Used
To delete all rows from a table:
DELETE FROM <table>;
Examples:
DELETE FROM logs;
DELETE FROM users;
DELETE FROM products;
See all of the SQL used in Modifying Data With SQL in the Modifying Data With SQL Cheatsheet.
[MUSIC]
0:00
Remember the four CRUD operations,
create, read, update, and delete.
0:04
We know the first three keywords too.
0:10
Insert to create, select to read,
and update to update.
0:12
Just like update, delete's keyword
is the same as the action.
0:16
Delete.
0:19
To write a delete statement,
you'd write something like this.
0:20
DELETE FROM table name.
0:23
The delete keyword removes
rows from a table.
0:26
It doesn't just empty the rows' values,
it removes the rows altogether.
0:30
Let's delete all the data from a table.
0:35
Let’s imagine we’ve had the sad news
that our library was closing down.
0:38
We’ve sold all the books in our library,
and
0:43
we need to get rid of all
the personal data in our library.
0:45
Let’s use the DELETE FROM statement to
remove all data from the books table.
0:49
When we view the books table now,
there are no rows remaining.
0:58
Now how about wiping out
all of the sensitive
1:02
information from the patrons table?
1:05
We can just modify the delete from
book state to say delete from patrons.
1:08
Simple.
1:16
When we execute this now, all of
the patron information has been removed.
1:17
It's important to note,
you can't undo this.
1:22
Without a backup of your data,
you can't restore it.
1:24
You need to sign up for Treehouse in order to download course files.
Sign up