0
0
SQLquery~5 mins

DELETE without WHERE (danger) in SQL

Choose your learning style9 modes available
Introduction

Deleting data removes rows from a table. Using DELETE without a WHERE clause deletes all rows, which can cause data loss.

You want to clear all records from a table quickly.
You are resetting a test database to empty state.
You want to remove all data before importing fresh data.
You accidentally run DELETE without WHERE and lose data (to learn caution).
Syntax
SQL
DELETE FROM table_name;

This deletes all rows in the table.

Be very careful: no filter means complete data loss in that table.

Examples
Deletes every row in the employees table.
SQL
DELETE FROM employees;
Deletes only orders before 2023, showing safe use with WHERE.
SQL
DELETE FROM orders WHERE order_date < '2023-01-01';
Sample Program

This example creates a table, inserts 3 rows, shows them, deletes all rows without WHERE, then shows the empty table.

SQL
CREATE TABLE fruits (id INT, name VARCHAR(20));
INSERT INTO fruits VALUES (1, 'Apple'), (2, 'Banana'), (3, 'Cherry');
SELECT * FROM fruits;
DELETE FROM fruits;
SELECT * FROM fruits;
OutputSuccess
Important Notes

Always double-check your DELETE statements before running.

Use transactions or backups to recover if you delete too much.

Consider using TRUNCATE for fast full table deletion if supported.

Summary

DELETE without WHERE removes all rows in a table.

This can cause accidental data loss if not careful.

Always confirm your DELETE commands before executing.