SQL UPDATE Statement: Modifying Rows & Safe Best Practices

The UPDATE statement is a core Data Manipulation Language (DML) command used to modify existing values in table columns. Unlike INSERT (which adds new rows), UPDATE alters attributes in rows that already exist.


Standard UPDATE Syntax

UPDATE table_name
SET column1 = new_value1, column2 = new_value2
WHERE filter_condition;

Hands-on Updating Scenarios

-- 1. Update single column for a specific student
UPDATE students
SET gpa = 3.90
WHERE student_id = 1;

-- 2. Update multiple columns simultaneously
UPDATE students
SET course = 'MCA', gpa = 3.82
WHERE student_id = 4;

-- 3. Perform mathematical updates (e.g., 5% scholarship boost)
UPDATE students
SET gpa = gpa + 0.10
WHERE course = 'BCA' AND gpa <= 3.80;
Safety Golden Rule: Always run a SELECT query with the exact same WHERE condition before running an UPDATE to verify which rows will be affected!

Next, let us learn how to remove records safely using the SQL DELETE Statement!

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!