🔧 Quick Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2
WHERE some_condition;
This is like telling SQL:
“Hey, go find a specific row, and change this or that value.”
🧾 Here’s the current friends
table:
id |
name |
age |
phone |
1 | Olivia | 27 | 5559831220 |
2 | Mason | 23 | 5556712345 |
3 | Zoe | 30 | 5559083344 |
4 | Ethan | 21 | 5554421199 |
5 | Harper | 25 | 5557882910 |
✅ Example 1: Change Mason’s age to 24
UPDATE friends
SET age = 24
WHERE name = 'Mason';
💡 Output:
Query OK, 1 row affected
Table Now:
✅ Example 2: Update Harper’s phone number
UPDATE friends
SET phone = '5552223344'
WHERE name = 'Harper';
💡 Output:
Query OK, 1 row affected
Updated Table:
⚠️ Important: Don’t Forget the WHERE Clause
UPDATE friends
SET age = 50;
⚠️ This will change everyone’s age to 50 😱 — because there’s no filter.
Always use WHERE
unless you truly want to update all rows.
✅ Example 3: Update multiple columns at once
UPDATE friends
SET age = 26, phone = '5550001234'
WHERE name = 'Olivia';
💡 Output:
Query OK, 1 row affected
Olivia’s Updated Info:
🧃 Recap
UPDATE
lets you change data that’s already in the table
- Always use
WHERE
to avoid updating everything by accident
- You can update one or multiple columns at once
- Perfect for fixing mistakes or updating info