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

Mysql Update Statement

The document discusses the MySQL UPDATE statement which is used to modify existing records in a table. It provides the basic UPDATE syntax, notes to be careful when omitting the WHERE clause as it will update all records, and examples of updating a single record and multiple records based on a condition. It also warns users to be careful when updating records and to always include a WHERE clause to specify which records to update.

Uploaded by

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

Mysql Update Statement

The document discusses the MySQL UPDATE statement which is used to modify existing records in a table. It provides the basic UPDATE syntax, notes to be careful when omitting the WHERE clause as it will update all records, and examples of updating a single record and multiple records based on a condition. It also warns users to be careful when updating records and to always include a WHERE clause to specify which records to update.

Uploaded by

salimdz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

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

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

MySQL UPDATE Statement


❮ Previous Next ❯

The MySQL 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 in the Northwind sample database:
CustomerID
Tutorials  Exercises  Services 
CustomerName ContactName

Address City
Sign Up Log in
PostalCode

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

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 London WA1 1DP


Hanover
Sq.

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 PostalCod

1 Alfreds Alfred Schmidt Obere Str. Frankfurt 12209


Futterkiste 57
2 Tutorials  AnaExercises
Trujillo
Emparedados y

Ana Trujillo
Services 
Avda.
 de la
Constitución
México
D.F.
Sign Up 05021
Log in

HTML
 CSS helados
JAVASCRIPT SQL PYTHON JAVA2222PHP HOW TO W3.CSS C

3 Antonio Moreno Antonio Mataderos México 05023


Taquería Moreno 2312 D.F.

4 Around the Horn Thomas Hardy 120 London WA1 1DP


Hanover
Sq.

UPDATE Multiple Records


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

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

Example

UPDATE Customers
SET PostalCode = 00000
WHERE Country = 'Mexico';

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

CustomerID CustomerName ContactName Address City PostalCod

1 Alfreds Alfred Schmidt Obere Str. Frankfurt 12209


Futterkiste 57

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


Emparedados y Constitución D.F.
helados 2222
 Tutorials  Exercises  Services   Sign Up Log in
3 Antonio Moreno Antonio Mataderos México 00000
HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Taquería Moreno 2312 D.F.

4 Around the Horn Thomas Hardy 120 London WA1 1DP


Hanover
Sq.

Update Warning!

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

Example

UPDATE Customers
SET PostalCode = 00000;

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

CustomerID CustomerName ContactName Address City PostalCod

1 Alfreds Alfred Schmidt Obere Str. Frankfurt 00000


Futterkiste 57

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


Emparedados y Constitución D.F.
helados 2222

3 Antonio Moreno Antonio Mataderos México 00000


Taquería Moreno 2312 D.F.
4 Tutorials  Exercises 
Around the Horn
Services 
Thomas Hardy 120

London
Sign Up
00000
Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVAHanover
PHP HOW TO W3.CSS C
Sq.

Test Yourself With Exercises

Exercise:
Update the City column of all records in the Customers table.

Customers
City = 'Oslo';

Submit Answer »

Start the Exercise

❮ Previous Log in to track progress Next ❯


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

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

COLOR PICKER


 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

 SPACES UPGRADE NEWSLETTER

GET CERTIFIED REPORT ERROR


Top Tutorials Top References
 Tutorials 
HTML Tutorial
Exercises  Services  
HTML Reference
Sign Up Log in

HTML
 CSS CSS Tutorial
JAVASCRIPT SQL PYTHON CSS Reference PHP
JAVA HOW TO W3.CSS C
JavaScript Tutorial JavaScript Reference
How To Tutorial SQL Reference
SQL Tutorial Python Reference
Python Tutorial W3.CSS Reference
W3.CSS Tutorial Bootstrap Reference
Bootstrap Tutorial PHP Reference
PHP Tutorial HTML Colors
Java Tutorial Java Reference
C++ Tutorial Angular Reference
jQuery Tutorial 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
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
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-2023 by Refsnes Data. All Rights Reserved. W3Schools is Powered by


W3.CSS.

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

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

You might also like