Labs ICT
โญ Pro Login

UPDATE

Data changes over time. Students get older, scores get improved, cities change. That is what UPDATE is for.

Basic UPDATE

-- Update a single column for a specific student
UPDATE students SET score = 96 WHERE name = 'Amina';

Always use WHERE with UPDATE. I mean it. If you forget WHERE, you will update every single row in the table. There is no undo button in SQL.

Updating Multiple Columns

UPDATE students SET age = 23, score = 90 WHERE name = 'Zainab';

Updating All Rows (Deliberately)

Sometimes you actually want to update every row. For example, giving everyone a 5-point bonus:

UPDATE students SET score = score + 5;

See? No WHERE clause. Every student's score goes up by 5. This is intentional, but it is also why you should double-check your UPDATE statements before running them on a real production database.

UPDATE with Conditions

-- Give bonus points only to students from Kano
UPDATE students SET score = score + 3 WHERE city = 'Kano';

-- Check the results
SELECT name, city, score FROM students;

๐Ÿงช Quick Quiz

What happens if you run UPDATE without a WHERE clause?