Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Removing Data from All Rows in a Table1:27 with Andrew Chalkley
In this video we'll see how to delete all data from a table.
To delete all rows from a table:
DELETE FROM <table>;
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.
Remember the four CRUD operations, create, read, update, and delete.
We know the first three keywords too.
Insert to create, select to read, and update to update.
Just like update, delete's keyword is the same as the action.
To write a delete statement, you'd write something like this.
DELETE FROM table name.
The delete keyword removes rows from a table.
It doesn't just empty the rows' values, it removes the rows altogether.
Let's delete all the data from a table.
Let’s imagine we’ve had the sad news that our library was closing down.
We’ve sold all the books in our library, and
we need to get rid of all the personal data in our library.
Let’s use the DELETE FROM statement to remove all data from the books table.
When we view the books table now, there are no rows remaining.
Now how about wiping out all of the sensitive
information from the patrons table?
We can just modify the delete from book state to say delete from patrons.
When we execute this now, all of the patron information has been removed.
It's important to note, you can't undo this.
Without a backup of your data, you can't restore it.
You need to sign up for Treehouse in order to download course files.Sign up