SQL > SQL Commands > Update Statement

The UPDATE statement is used to modify data in a database table.

The SQL UPDATE statement changes existing rows in a table — you can update one or many columns at a time, and the WHERE clause controls which rows are affected. Without a WHERE clause, every row is updated.

Syntax

UPDATE can be used to modify one column at a time or multiple columns at a time. The syntax for updating a single column is as follows:

UPDATE "table_name"
SET "column_1" = [new value]
WHERE "condition";

The syntax for updating multiple columns is as follows:

UPDATE "table_name"
SET column_1 = [value1], column_2 = [value2], ...
WHERE "condition";

Examples

We use the following table for our examples.

Table Store_Information

 Store_Name  Sales  Txn_Date 
 Los Angeles  1500  Jan-05-1999 
 San Diego  250  Jan-07-1999 
 Los Angeles  300  Jan-08-1999 
 Boston  700  Jan-08-1999 

Example 1: Update a single column

We notice that the sales for Los Angeles on Jan-08-1999 is actually $500 instead of $300, and that particular entry needs to be updated. To do so, we use the following SQL query:

UPDATE Store_Information
SET Sales = 500
WHERE Store_Name = 'Los Angeles'
AND Txn_Date = 'Jan-08-1999';

The resulting table would look like

Table Store_Information

 Store_Name  Sales  Txn_Date 
 Los Angeles  1500  Jan-05-1999 
 San Diego  250  Jan-07-1999 
 Los Angeles  500  Jan-08-1999 
 Boston  700  Jan-08-1999 

In this case, there is only one row that satisfies the condition in the WHERE clause. If there are multiple rows that satisfy the condition, all of them will be modified. If no WHERE clause is specified, all rows will be modified.

Example 2: Update multiple columns

We notice that the 'San Diego' entry has the wrong Sales and TXN_Date information. To fix it, we run the following SQL statement:

UPDATE Store_Information
SET Sales = 600, Txn_Date = 'Jan-15-1999'
WHERE Store_Name = 'San Diego';

The table now becomes,

Table Store_Information

 Store_Name  Sales  Txn_Date 
 Los Angeles  1500  Jan-05-1999 
 San Diego  600  Jan-15-1999 
 Los Angeles  500  Jan-08-1999 
 Boston  700  Jan-08-1999 

IMPORTANT: When using the UPDATE statement, pay special attention to make sure that some type of filtering criteria is specified. Otherwise, the value of all rows can be changed.

Frequently Asked Questions

What is the difference between UPDATE and INSERT in SQL?

INSERT adds new rows to a table, while UPDATE modifies values in rows that already exist. Use INSERT when you need to add data and UPDATE when you need to change existing data.

How do I UPDATE only the first N rows in SQL?

Most databases support a LIMIT clause (MySQL) or TOP clause (SQL Server) in an UPDATE: e.g., UPDATE table SET col = val WHERE condition LIMIT 10; In other databases you may need a subquery targeting specific row IDs.

Can I use UPDATE with a JOIN in SQL?

Yes. Most databases allow UPDATE with a JOIN to update rows based on values from another table. The exact syntax varies: MySQL uses UPDATE t1 JOIN t2 ON ... SET t1.col = t2.col, while SQL Server uses UPDATE t1 SET col = t2.col FROM t1 JOIN t2 ON ...

Is SQL UPDATE reversible?

Inside an open transaction (before COMMIT), you can roll back an UPDATE with ROLLBACK. Once committed, the change is permanent unless you restore from a backup. Always test UPDATE statements with a SELECT using the same WHERE clause first.

Exercises

1. Using the same Store_Information table right above, what data is in the table after the following SQL statement is executed?
UPDATE Store_Information
SET Sales = 800
WHERE Store_Name = 'Boston';

2. Continuing to use the same table. What is the content of the table after the following SQL statement is executed?
UPDATE Store_Information
SET Sales = 2000
WHERE Store_Name = 'Los Angeles' AND Txn_Date = 'Jan-10-1999';

3. Again using the same table. What is the content of the table after the following SQL statement is executed?
UPDATE Store_Information
SET Sales = 1000;

Next: SQL DELETE FROM

This page was last updated on March 19, 2026.




Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact