DELETE

SQL · Modifying Data

Theory

DELETE removes rows from a table. DELETE FROM employees WHERE city = 'Pune' removes only the employees in Pune; the table and its other rows stay. Without a WHERE clause, every row is deleted, but the empty table remains (unlike DROP TABLE).

DELETE works row by row: each removed row is logged, DELETE triggers fire, and foreign keys are checked, so deleting a customer who still has orders is blocked unless the foreign key uses ON DELETE CASCADE or SET NULL. Because it is ordinary DML, it can be rolled back inside a transaction. On big tables, deleting millions of rows is slow; delete in batches, or use TRUNCATE when every row must go. Many teams prefer a soft delete (an is_active flag) so history is kept.

Why we use it

Data sometimes must go: test records, cancelled sign-ups, rows past their retention period, or personal data a customer asked to remove. DELETE removes exactly the rows you choose and nothing else.

When to use it

Use DELETE with WHERE to remove specific rows. Use TRUNCATE to empty a whole table quickly, DROP TABLE to remove the table itself, and a soft-delete flag when you may need the history later.

How it works

  1. DELETE FROM employees WHERE ...
  2. Read the next row
  3. Does it match the WHERE condition? Yes: Check foreign keys and fire triggers. No: Keep the row.
  4. Is the delete allowed? Yes: Remove and log the row. No: Error: referenced by child rows.
  5. Report how many rows were deleted

Syntax

DELETE FROM table
WHERE condition;

Example

DELETE FROM employees WHERE name = 'Asha Rao';

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic