Lesson 11: Deleting Data

15 min read Beginner Lesson 11 of 12 6.7k learners

Introduction

The DELETE statement removes rows from a table. To delete safely, always use a WHERE clause. Otherwise, all rows will be deleted!

Deleting a Single Row

SQL
DELETE FROM customers
WHERE customer_id = 5;

Deleting Multiple Rows

If the WHERE condition matches more than one row, they will all be removed.

SQL
DELETE FROM customers
WHERE city = 'Chicago';

Deleting All Rows

Omitting the WHERE clause deletes every row in the table.

SQL
DELETE FROM customers;

DELETE vs TRUNCATE

  • DELETE: Removes rows one by one, can use WHERE, logs each deletion.
  • TRUNCATE: Removes all rows instantly, cannot use WHERE, minimal logging.

Practice Quiz

Test your knowledge about deleting data:

1. Which keyword deletes rows from a table?
2. What happens if you run DELETE without WHERE?
3. Which statement removes all rows faster but cannot use WHERE?
4. Which is safer for removing specific rows?
5. Which statement removes the entire table structure?