SQL LESSON 27 OF 32

UPDATE safely

UPDATE changes existing rows. WHERE limits which rows change; without it every row is affected. Preview the same condition with SELECT before changing production data. Our database is temporary sample data.

हिन्दी में समझें

UPDATE पुराने मान बदलता है। WHERE प्रभावित पंक्तियाँ सीमित करता है; बिना WHERE सभी बदलेंगी। असली डेटा पर पहले उसी शर्त का SELECT देखें। यहाँ अस्थायी नमूना है।

अभ्यास: ग्राहक id 2 का city Bengaluru करें और वह पंक्ति दिखाएँ।

Hinglish mein samjhein

UPDATE existing rows badalta hai. WHERE scope limit karta hai; bina WHERE sab rows change hongi. Production mein pehle same condition SELECT karo. Yahan temporary sample data hai.

Practice: Customer id 2 ki city Bengaluru karo aur woh row select karo.

A small SQL example

UPDATE customers SET city='Agra' WHERE id=1;
SELECT * FROM customers WHERE id=1;

Examples use the fictional shop database bundled with the SQL playground: customers, products, orders, order_items and employees. The engine is SQLite; other SQL dialects may differ.

Try this example in the SQL playground →

Practise this idea

Change customer id 2 city to Bengaluru, then select that row.

Check answer & explanation
UPDATE customers SET city='Bengaluru' WHERE id=2; SELECT * FROM customers WHERE id=2;

The WHERE id=2 condition limits the update to Ravi. The final SELECT verifies the new city without changing other customers.

Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.

Check your understanding

UPDATE without WHERE affects…

  1. Every row
  2. No rows
  3. Only the first row
Check the quiz answer

Every row

UPDATE changes existing rows. WHERE limits which rows change; without it every row is affected. Preview the same condition with SELECT before changing production data. Our database is temporary sample data.

References & corrections

Use the official SQLite documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.

FROM LEARNING TO BUSINESS RESULTS

Need a dashboard for your team?

Excel Keys designs custom Excel and HTML dashboards around your own KPIs and Excel files. They run offline in the browser, so your data stays on your computer.