📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PostgreSQL Essentials UPDATE and DELETE

UPDATE and DELETE

5 min read
UPDATE changes rows — always add a WHERE clause or every row gets updated. DELETE removes rows — always use WHERE too. TRUNCATE is faster for deleting all rows but resets sequences and cannot be filtered.

Updating and Deleting Rows

-- Update
UPDATE users SET age = 29 WHERE id = 1;
UPDATE users SET age = age + 1 WHERE age < 18;

-- Delete specific rows
DELETE FROM users WHERE id = 5;

-- Delete all rows (keep table)
TRUNCATE users;

-- Safe pattern — preview first
SELECT * FROM users WHERE age < 18; -- check before deleting