0% found this document useful (0 votes)
3 views

SQL UPDATE Statement

The SQL UPDATE statement is used to modify existing records in a table, with a syntax that includes specifying the table name, setting new values for columns, and using a WHERE clause to determine which records to update. Omitting the WHERE clause will result in all records being updated, which can lead to unintended changes. Examples demonstrate how to update single and multiple records in a 'Customers' table.

Uploaded by

soha.adel66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

SQL UPDATE Statement

The SQL UPDATE statement is used to modify existing records in a table, with a syntax that includes specifying the table name, setting new values for columns, and using a WHERE clause to determine which records to update. Omitting the WHERE clause will result in all records being updated, which can lead to unintended changes. Examples demonstrate how to update single and multiple records in a 'Customers' table.

Uploaded by

soha.adel66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1/22/25, 5:55 PM SQL UPDATE Statement

 Tutorials  Exercises  Certificates  Services  Search...  Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

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;

https://www.w3schools.com/sql/sql_update.asp 1/13
1/22/25, 5:55 PM SQL UPDATE Statement

Note: Be careful when updating records in a table! Notice the WHERE clause in the UPDATE statement. The WHERE
 Tutorials  Exercises  Certificates  Services   Sign Up Log in
clause specifies which record(s) that should be updated. If you omit the WHERE clause, all records in the table will be
updated!
HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

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

CustomerID CustomerName ContactName Address City PostalCode Country

1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany

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


Emparedados y helados Constitución 2222 D.F.

3 Antonio Moreno Antonio Moreno Mataderos 2312 México 05023 Mexico


Taquería D.F.

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

5 Berglunds snabbköp Christina Berguvsvägen 8 Luleå S-958 22 Sweden


Berglund

UPDATE Table
https://www.w3schools.com/sql/sql_update.asp 2/13
1/22/25, 5:55 PM SQL UPDATE Statement

The following SQL statement updates the first customer (CustomerID = 1) with a new contact person and a new city.
 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R
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 PostalCode Country

1 Alfreds Futterkiste Alfred Schmidt Obere Str. 57 Frankfurt 12209 Germany

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


Emparedados y helados Constitución 2222 D.F.

3 Antonio Moreno Antonio Moreno Mataderos 2312 México 05023 Mexico


Taquería D.F.

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

5 Berglunds snabbköp Christina Berguvsvägen 8 Luleå S-958 22 Sweden


Berglund

ADVERTISEMENT
https://www.w3schools.com/sql/sql_update.asp 3/13
1/22/25, 5:55 PM SQL UPDATE Statement

 Tutorials  Exercises  Certificates  Services   Sign Up Log in


UPDATE Multiple Records
HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R
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
UPDATE Customers
SET ContactName='Juan'
WHERE Country='Mexico';

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

CustomerID CustomerName ContactName Address City PostalCode Country

1 Alfreds Futterkiste Alfred Schmidt Obere Str. 57 Frankfurt 12209 Germany

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


Emparedados y helados Constitución 2222 D.F.

3 Antonio Moreno Juan Mataderos 2312 México 05023 Mexico


Taquería D.F.

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

https://www.w3schools.com/sql/sql_update.asp 4/13
1/22/25, 5:55 PM SQL UPDATE Statement

5 Tutorials  Berglunds
Exercisessnabbköp

Christina
Certificates 
Berglund
Services  Berguvsvägen 8 Luleå  S-958 22
Sign UpSweden
Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

Update Warning!

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

Example
UPDATE Customers
SET ContactName='Juan';

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

CustomerID CustomerName ContactName Address City PostalCode Country

1 Alfreds Futterkiste Juan Obere Str. 57 Frankfurt 12209 Germany

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


Emparedados y helados Constitución 2222 D.F.

https://www.w3schools.com/sql/sql_update.asp 5/13
1/22/25, 5:55 PM SQL UPDATE Statement

3 Tutorials  Antonio Moreno


Exercises
Taquería
 CertificatesJuan
 Services  Mataderos 2312 México
D.F.
 05023
Sign UpMexico
Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R
4 Around the Horn Juan 120 Hanover Sq. London WA1 1DP UK

5 Berglunds snabbköp Juan Berguvsvägen 8 Luleå S-958 22 Sweden

?
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

Submit Answer »

https://www.w3schools.com/sql/sql_update.asp 6/13
1/22/25, 5:55 PM SQL UPDATE Statement

❮ Previous
Tutorials  Exercises  Certificates  Services   Log❯in
Sign Up Next

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

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

ADVERTISEMENT

https://www.w3schools.com/sql/sql_update.asp 7/13
1/22/25, 5:55 PM SQL UPDATE Statement

 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

https://www.w3schools.com/sql/sql_update.asp 8/13
1/22/25, 5:55 PM SQL UPDATE Statement

 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

COLOR PICKER


ADVERTISEMENT

https://www.w3schools.com/sql/sql_update.asp 9/13
1/22/25, 5:55 PM SQL UPDATE Statement

 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

ADVERTISEMENT

https://www.w3schools.com/sql/sql_update.asp 10/13
1/22/25, 5:55 PM SQL UPDATE Statement

 Tutorials 
ADVERTISEMENT
Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

 PLUS SPACES GET CERTIFIED FOR TEACHERS

FOR BUSINESS CONTACT US

Top Tutorials Top References


HTML Tutorial HTML Reference
CSS Tutorial CSS Reference
JavaScript Tutorial JavaScript Reference
How To Tutorial SQL Reference
SQL Tutorial Python Reference
Python Tutorial W3.CSS Reference
W3.CSS Tutorial Bootstrap Reference
https://www.w3schools.com/sql/sql_update.asp 11/13
1/22/25, 5:55 PM SQL UPDATE Statement
Bootstrap Tutorial PHP Reference

 Tutorials PHP
 Tutorial
Exercises 
Java Tutorial
Certificates  HTML Colors
Services 
Java Reference
 Sign Up Log in
C++ Tutorial Angular Reference
HTML
 CSS jQuery Tutorial
JAVASCRIPT SQL PYTHON jQuery Reference
JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R
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
W3.CSS 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.

https://www.w3schools.com/sql/sql_update.asp 12/13
1/22/25, 5:55 PM SQL UPDATE Statement
Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

https://www.w3schools.com/sql/sql_update.asp 13/13

You might also like