✏️ UPDATE – How to Change Data in SQL

🔧 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
1Olivia275559831220
2Mason235556712345
3Zoe305559083344
4Ethan215554421199
5Harper255557882910

✅ Example 1: Change Mason’s age to 24

UPDATE friends
SET age = 24
WHERE name = 'Mason';

💡 Output:

Query OK, 1 row affected

Table Now:

2Mason245556712345

✅ Example 2: Update Harper’s phone number

UPDATE friends
SET phone = '5552223344'
WHERE name = 'Harper';

💡 Output:

Query OK, 1 row affected

Updated Table:

5Harper255552223344

⚠️ 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:

1Olivia265550001234

🧃 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

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top