Code has been added to clipboard!

How to Use SQL UPDATE

Reading time 1 min
Published Aug 9, 2017
Updated Oct 9, 2019

TL;DR - The SQL UPDATE command allows you to modify the data records in the table. It is usually used together with the WHERE clause: if you don't use it, all the records in the table will be updated.

The syntax for SQL UPDATE

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

Examples using a demo database

The Developers table

ID Name City Country
1 Tom Kurkutis New York USA
2 Ana Fernandez London UK
3 Antonio Indigo Paris France
4 Aarav Kaelin Delhi India
5 Andrew Tumota Miami USA

Updating a single entry

Example
UPDATE Developers
SET City = 'Berlin', Country= 'Germany'
WHERE Name = 'Antonio Indigo';

The result

ID Name City Country
1 Tom Kurkutis New York USA
2 Ana Fernandez London UK
3 Antonio Indigo Berlin Germany
4 Aarav Kaelin Delhi India
5 Andrew Tumota Miami USA

Updating entries that comply with a defined condition

Example
UPDATE Developers
SET Name='Ben'
WHERE Country='India';

The result

ID Name City Country
1 Tom Kurkutis New York USA
2 Ana Fernandez London UK
3 Antonio Indigo Berlin Germany
4 Ben Delhi India
5 Andrew Tumota Miami USA

Updating all the entries

Example
UPDATE Developers
SET Name='Ben';

The result

ID Name City Country
1 Ben New York USA
2 Ben London UK
3 Ben Berlin Germany
4 Ben Delhi India
5 Ben Miami USA
Learn SQL
Introduction
Syntax
Data Types
Server Data Types
Commands
Commands List
Wildcards
Constraints
Aggregate Functions
Date Functions
Date Format
Injection
SQL Server Hosting
Views
Auto-incrementation
SQL Operators
AS
AND & OR
IN
BETWEEN
WHERE
GROUP BY
HAVING
ORDER BY
LIKE
NOT
NOT EQUAL
UNION
NULL
NOT NULL
DEFAULT
UNIQUE
FOREIGN KEY
PRIMARY KEY
CHECK
Indexes
ALTER TABLE
CREATE DATABASE
CREATE TABLE
DELETE
DROP
INSERT INTO SELECT
INSERT INTO
SELECT
SELECT DISTINCT
SELECT INTO
SELECT TOP
UPDATE
FULL OUTER JOIN
INNER JOIN
JOIN
LEFT JOIN
RIGHT JOIN
AVG()
COUNT
FIRST
LAST
MAX
MIN()
SUM()
LEN
UCASE
MID
NOW
ROUND
FORMAT
LOWER
CONVERT
ISNULL