SQL UPDATE vs INSERT: Modify Data in SQL Tables


If you’re learning SQL, it’s important to understand how to modify data. A common question beginners ask is the difference between SQL UPDATE vs INSERT. These two commands serve very different purposes in SQL databases: INSERT is used to add new data, while UPDATE is used to change existing records.

In this post, I will show you what is an UPDATE query, how to update values in your database, and how to handle common update scenarios using real-world SQL examples.

SQL UPDATE vs INSERT: What’s the Difference?

INSERTUPDATE
Adds new records to a tableModifies existing records in a table
INSERT INTO ... VALUES (...)UPDATE ... SET ... WHERE ...
YesNo
NoYes

Use INSERT when you’re adding something new. Use UPDATE when you’re correcting or changing something that already exists.

Here is what they look like in SQL Server Management Studio:

SQL UPDATE vs INSERT

What Is an UPDATE Query?

An UPDATE query in SQL is used to change the values of one or more columns in existing rows.

Here’s the basic syntax:

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

Example: Update customer’s city

UPDATE Customers
SET City = 'London'
WHERE CustomerID = 'ISLAT'

This updates the city for the customer with ID = ‘ISLAT’.

Here is what it looks like in SSMS:

SQL Update with Where

Once you execute this code, you will see that the value changed for the customer with ID = ‘ISLAT’:

SQL UPDATE then SELECT

Update Value in Database

Let’s say you want to increase all employee bonuses by 10%:

UPDATE EmployeeBonus
SET Amount = Amount * 1.10

This updates every row in the EmployeeBonus table:

UPDATE Value in Database

SQL UPDATE Without WHERE

Updating all of the records inside the table is not always a good thing. A common mistake is running an UPDATE without a WHERE clause, which updates every row in the table – often unintentionally.

Here is the example:

UPDATE Products
SET Price = 0

This would set the price of every product to 0. Always double-check your WHERE clause when updating!

SQL UPDATE for Each Row in SELECT

You can combine UPDATE with JOIN or EXISTS to update rows based on another query:

Example: Update each order’s ship address using Customers as a lookup table:

UPDATE ord
SET ord.ShipAddress = cust.Address
FROM Orders ord
JOIN Customers cust ON ord.CustomerID = cust.CustomerID

This updates each order’s ShipAddress using the matching customer record:

SQL UPDATE for Each Row in SELECT

SQL UPDATE IS NULL

You can use IS NULL to update records that have missing data.

Example:

UPDATE Customers
SET Region = 'Not Provided'
WHERE Region IS NULL

This fills in missing Region with the value ‘Not Provided’ instead of NULL:

SQL UPDATE IS NULL

SQL UPDATE to NULL

To clear a value in a column, you can set it to NULL.

Example:

UPDATE Products
SET CategoryID = NULL
WHERE UnitsInStock = 0

This removes the CategoryID for products that have 0 units in stock:

SQL UPDATE to NULL

SQL UPDATE to Uppercase

SQL’s UPPER() function helps you standardize data by converting text to uppercase.

Example:

UPDATE Products
SET ProductName = UPPER(ProductName)

All product names will now be in capital letters:

SQL UPDATE to Uppercase

Conclusion

Understanding the difference between SQL UPDATE vs INSERT is key to managing your database effectively. Use INSERT when you’re adding new data and UPDATE when you’re modifying existing records. With the examples above, you now know how to:

  • Update specific values in a database
  • Avoid updating all rows accidentally
  • Handle NULL values
  • Use UPDATE with SELECT or JOIN
  • Format text using UPPER()

Mastering the UPDATE statement gives you powerful control over your SQL tables – and helps ensure your data stays clean and accurate.

If you missed my previous SQL blog post on How to Insert Data in SQL Database, make sure you check it out here.

If you would like to learn more about SQL queries, make sure you buy this book: T-SQL Fundamentals (Developer Reference)


Add a Comment

Your email address will not be published. Required fields are marked *