Lesson 19 Intermediate Level
19 of 30 lessons

DELETE Statement

Learn how to remove data from tables using DELETE statements with WHERE clause. The DELETE statement is essential for data management.

Introduction

The DELETE statement removes existing rows from a table based on a condition.

Basic Syntax

DELETE FROM table_name
WHERE condition;

Example: Delete Employee by ID

DELETE FROM employees
WHERE employee_id = 101;

Delete Multiple Rows

DELETE FROM employees
WHERE department_id = 10;

Delete All Rows

Warning: Omitting the WHERE clause deletes all rows from the table.

DELETE FROM employees;

Best Practices

  • Always use WHERE clause to avoid accidental deletion of all data.
  • Test your WHERE condition with a SELECT first.
  • Use transactions (COMMIT and ROLLBACK) for safety.

Practice Task

  • Delete employee with employee_id 105.
  • Remove all employees from a specific department.
  • Try deleting all rows from a test table (use with caution).