0% found this document useful (0 votes)
5 views10 pages

SQL UPDATE Statement Explained

The SQL UPDATE statement is used to modify existing records in a table. It requires a specific syntax that includes the table name, the columns to be updated, and a WHERE clause to specify which records to update, as omitting the WHERE clause will update all records. Examples demonstrate how to update single and multiple records in a Customers table.

Uploaded by

matias bahiru
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

SQL UPDATE Statement Explained

The SQL UPDATE statement is used to modify existing records in a table. It requires a specific syntax that includes the table name, the columns to be updated, and a WHERE clause to specify which records to update, as omitting the WHERE clause will update all records. Examples demonstrate how to update single and multiple records in a Customers table.

Uploaded by

matias bahiru
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

7/15/25, 10:29 AM SQL UPDATE Statement

 Tutorials  Exercises  Services   Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C

SQL UPDATE Statement


❮ Previous Next ❯

The SQL UPDATE Statement


The UPDATE statement is used to modify the existing records in a table.

UPDATE Syntax

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

Note: Be careful when updating records in a table! Notice the WHERE clause in the
UPDATE statement. The WHERE clause specifies which record(s) that should be updated.
If you omit the WHERE clause, all records in the table will be updated!

Demo Database
Below is a selection from the Customers table used in the examples:

[Link] 1/10
7/15/25, 10:29 AM SQL UPDATE Statement

CustomerID
Tutorials  Exercises  Services 
CustomerName ContactName

Address City
Sign In
PostalCo

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
1 Alfreds Maria Anders Obere Str. 57 Berlin 12209
Futterkiste

2 Ana Trujillo Ana Trujillo Avda. de la México 05021


Emparedados y Constitución D.F.
helados 2222

3 Antonio Moreno Antonio Mataderos México 05023


Taquería Moreno 2312 D.F.

4 Around the Horn Thomas Hardy 120 Hanover London WA1 1DP
Sq.

5 Berglunds Christina Berguvsvägen Luleå S-958 22


snabbköp Berglund 8

 

UPDATE Table
The following SQL statement updates the first customer (CustomerID = 1) with a new
contact person and a new city.

Example Get your own SQL Server

UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;

The selection from the "Customers" table will now look like this:

CustomerID CustomerName ContactName Address City PostalC

1 Alfreds Alfred Schmidt Obere Str. 57 Frankfurt 12209


Futterkiste

[Link] 2/10
7/15/25, 10:29 AM SQL UPDATE Statement

2 Tutorials  AnaExercises
Trujillo

Emparedados y
Ana Trujillo
Services 
Avda.
 de la
Constitución
México
D.F.
05021
Sign In

HTML
 CSS helados
JAVASCRIPT SQL PYTHON JAVA2222PHP HOW TO [Link] C

3 Antonio Moreno Antonio Mataderos México 05023


Taquería Moreno 2312 D.F.

4 Around the Horn Thomas Hardy 120 Hanover London WA1 1D


Sq.

5 Berglunds Christina Berguvsvägen Luleå S-958 2


snabbköp Berglund 8

ADVERTISEMENT

 

UPDATE Multiple Records


It is the WHERE clause that determines how many records will be updated.

The following SQL statement will update the ContactName to "Juan" for all records
where country is "Mexico":

Example

[Link] 3/10
7/15/25, 10:29 AM SQL UPDATE Statement

UPDATE Customers
Tutorials  Exercises 
SET ContactName='Juan'
Services   Sign In

WHERE Country='Mexico';
HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C

The selection from the "Customers" table will now look like this:

CustomerID CustomerName ContactName Address City PostalC

1 Alfreds Alfred Schmidt Obere Str. 57 Frankfurt 12209


Futterkiste

2 Ana Trujillo Juan Avda. de la México 05021


Emparedados y Constitución D.F.
helados 2222

3 Antonio Moreno Juan Mataderos México 05023


Taquería 2312 D.F.

4 Around the Horn Thomas Hardy 120 Hanover London WA1 1D


Sq.

5 Berglunds Christina Berguvsvägen Luleå S-958 2


snabbköp Berglund 8

 

Update Warning!

Be careful when updating records. If you omit the WHERE clause, ALL records will be
updated!

Example

[Link] 4/10
7/15/25, 10:29 AM SQL UPDATE Statement

UPDATE Customers
Tutorials  Exercises 
SET ContactName='Juan';
Services   Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C

The selection from the "Customers" table will now look like this:

CustomerID CustomerName ContactName Address City PostalC

1 Alfreds Juan Obere Str. 57 Frankfurt 12209


Futterkiste

2 Ana Trujillo Juan Avda. de la México 05021


Emparedados y Constitución D.F.
helados 2222

3 Antonio Moreno Juan Mataderos México 05023


Taquería 2312 D.F.

4 Around the Horn Juan 120 Hanover London WA1 1D


Sq.

5 Berglunds Juan Berguvsvägen Luleå S-958 2


snabbköp 8

 

?
Exercise
What is the purpose of the SQL UPDATE statement?

To add new records to a table

To delete records from a table

To modify existing records in a table

To retrieve records from a table

[Link] 5/10
7/15/25, 10:29 AM SQL UPDATE Statement

 Tutorials  Exercises  Services 


Submit Answer »
 Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C

❮ Previous Next ❯

Track your progress - it's free! Sign Up Log in

ADVERTISEMENT

[Link] 6/10
7/15/25, 10:29 AM SQL UPDATE Statement

 Tutorials  Exercises  Services   Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C

[Link] 7/10
7/15/25, 10:29 AM SQL UPDATE Statement

COLOR PICKER 
 Tutorials  Exercises  Services  Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C



ADVERTISEMENT

ADVERTISEMENT

[Link] 8/10
7/15/25, 10:29 AM SQL UPDATE Statement
ADVERTISEMENT

 Tutorials  Exercises  Services   Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C

 

 PLUS SPACES

GET CERTIFIED FOR TEACHERS

FOR BUSINESS CONTACT US

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
[Link] Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference

[Link] 9/10
7/15/25, 10:29 AM SQL UPDATE Statement
SQL Reference

 Tutorials  Python Reference


Exercises 
[Link] Reference
Services   Sign In
Bootstrap Reference
HTML
 CSS PHP ReferenceSQL
JAVASCRIPT PYTHON JAVA PHP HOW TO [Link] C
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
[Link] Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate

    

FORUM ABOUT ACADEMY


W3Schools is optimized for learning and training. Examples might be simplified to improve
reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot
warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use,
cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by [Link].

[Link] 10/10

You might also like