Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

SQLite Tutorial

SQLite HOME SQLite Intro SQLite Get Started

SQLite SQL

SQLite SQL SQLite SELECT SQLite SELECT DISTINCT SQLite WHERE SQLite ORDER BY SQLite AND SQLite OR SQLite NOT SQLite INSERT INTO SQLite NULL Values SQLite UPDATE SQLite DELETE SQLite LIMIT SQLite Aggregate SQLite MIN() and MAX() SQLite COUNT() SQLite SUM() SQLite AVG() SQLite LIKE SQLite Wildcards SQLite GLOB SQLite IN SQLite BETWEEN SQLite Aliases SQLite Joins SQLite INNER JOIN SQLite LEFT JOIN SQLite RIGHT JOIN SQLite FULL JOIN SQLite CROSS JOIN SQLite Self Join SQLite UNION SQLite UNION ALL SQLite INTERSECT and EXCEPT SQLite GROUP BY SQLite HAVING SQLite EXISTS SQLite Subqueries SQLite INSERT INTO SELECT SQLite CASE SQLite NULL Functions SQLite Comments SQLite Operators

SQLite Advanced

SQLite UPSERT SQLite RETURNING SQLite WITH (CTE) SQLite Window Functions SQLite JSON

SQLite Database

SQLite Create DB SQLite Attach DB SQLite Create Table SQLite Drop Table SQLite Alter Table SQLite Data Types SQLite STRICT Tables SQLite Constraints SQLite NOT NULL SQLite UNIQUE SQLite PRIMARY KEY SQLite FOREIGN KEY SQLite CHECK SQLite DEFAULT SQLite AUTOINCREMENT SQLite Generated Columns SQLite Create Index SQLite Views SQLite Triggers SQLite Dates SQLite Transactions SQLite PRAGMA SQLite Injection

SQLite Tools

SQLite Command Line SQLite Import and Export SQLite with Python

SQLite References

SQLite Functions

SQLite Exercises

SQLite Editor SQLite Quiz SQLite Exercises

SQLite UPDATE Statement


Share

The UPDATE Statement

The UPDATE statement changes existing records in a table.

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

Warning: Be careful when you update records. The WHERE clause decides which records are changed. If you leave out WHERE, all the records in the table are changed!


Update a Record

This example gives the first customer (CustomerID = 1) a new contact person and a new city:

Example

UPDATE Customers
SET ContactName = 'Lene Nilsson', City = 'Frankfurt'
WHERE CustomerID = 1;
Try it Yourself »


Update Many Records

The WHERE clause decides how many records are updated. This example changes the postal code of all the customers from Mexico:

Example

UPDATE Customers
SET PostalCode = '00000'
WHERE Country = 'Mexico';
Try it Yourself »

Update Warning!

If you leave out the WHERE clause, all the records are updated:

Example

UPDATE Customers
SET PostalCode = '00000';
Try it Yourself »

In the editor, you can click "Restore Database" to get the original data back. In a real database, you cannot!


Update With a Calculation

The new value can be calculated from the old value. This example raises the price of all the products in category 1 by 10%:

Example

UPDATE Products
SET Price = Price * 1.1
WHERE CategoryID = 1;
Try it Yourself »

What Does UPDATE Return?

An UPDATE statement returns no rows. It only changes the data.

When you run an UPDATE in our editor, you see the message "You have made changes to the database. Rows affected: 1". That message is written by the editor, not by SQLite. It tells you how many rows were changed.


Count the Changed Rows

SQLite remembers how many rows the last INSERT, UPDATE or DELETE changed. The changes() function returns that number. This example changes the postal code of the customers from Mexico, and then shows how many rows were changed:

Example

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

SELECT changes();
Try it Yourself »

See the Changed Rows

Add RETURNING at the end, and the UPDATE returns the changed rows, like a SELECT:

Example

UPDATE Customers
SET PostalCode = '00000'
WHERE Country = 'Mexico'
RETURNING CustomerName, PostalCode;
Try it Yourself »

Tip: Read more in the SQLite RETURNING chapter. In Python, cur.rowcount tells how many rows were changed. See the Python SQLite Update chapter.




Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

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, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.