UPDATE

The SQL UPDATE Statement

UPDATE changes existing records.

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Note: Be careful! The WHERE clause decides which rows are updated. If you leave it out, every row in the table is updated.

Update One Row

Example

Give customer 7 a city:

UPDATE Customers
SET City = 'Singapore', ContactName = 'Mei Lin Chen'
WHERE CustomerID = 7;

Running SELECT * FROM Customers WHERE CustomerID = 7; afterwards shows:

Result: 1 row

CustomerIDCustomerNameContactNameCityCountry
7Golden SpoonMei Lin ChenSingaporeSingapore

Update Multiple Rows

Example

Give every Support employee a 10% raise:

UPDATE Employees
SET Salary = Salary * 1.10
WHERE Department = 'Support';

Running SELECT FirstName, Department, Salary FROM Employees; afterwards shows:

Result: 6 rows

FirstNameDepartmentSalary
RahulSales72000
SaraSales58000
DavidSales61000
AnanyaSupport49500
JamesSupport73700
FatimaFinance80000

Update Warning!

-- Without WHERE, every product gets price 0!
UPDATE Products
SET Price = 0;

Tip: Before running an UPDATE or DELETE, run a SELECT with the same WHERE clause to see exactly which rows will change. In production, do it inside a transaction so you can ROLLBACK.