SQL – UPDATE
Modify existing rows in a table using the UPDATE statement with precise WHERE conditions.
Table of Contents
Data changes. Students move cities. Grades get corrected. Prices are updated. The UPDATE statement lets you modify existing rows in a table. It is powerful — and therefore dangerous without a WHERE clause. An UPDATE without WHERE modifies every single row in the table simultaneously.
The golden rule: always write and verify your WHERE condition first using a SELECT statement. Only after confirming the right rows are selected, swap SELECT for UPDATE. This habit will save you from costly mistakes.
Safe UPDATE workflow
-- Step 1: Verify the rows first
SELECT * FROM students WHERE name = 'Dev Patel';
-- Step 2: Now run the update
UPDATE students
SET grade = 'B', score = 75.0
WHERE name = 'Dev Patel';
Try It Yourself — Interactive SQL Editor
Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.
Key Points
- ALWAYS add WHERE to UPDATE or you change every row
- You can update multiple columns in one SET clause
- Use a transaction to safely test updates before committing
- UPDATE can use expressions: SET score = score + 5
Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.
In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.