T-SQL 101: 141 Updating data in a SQL Server table

An UPDATE statement is the way we change data in an existing row or multiple rows of a table. In the example above, I’ve said I want to update dbo.OrderContacts; that’s the table.
I asked SQL Server to set the OrderContact column to Terry Jones, but only where the OrderID is 1. That’s how we modify values in a table.
If I needed to modify more than one column, after Terry Jones, I could just put a comma, and then I don’t have to use the word SET again.
UPDATE dbo.OrderContacts
SET OrderContact = 'Terry Jones',
DueDate = '20250401'
WHERE OrderID = 1;
You must have a WHERE clause unless your intention is to modify all the rows. In fact, that’s another common mistake that people make, is that they highlight and execute an UPDATE statement and forget to include the WHERE clause, and they end up modifying the entire table. It’s a common “oops” moment. One common suggestion is to always write UPDATE statements (and DELETE statements) as SELECT statements first, to make sure you are affecting the rows you meant to affect.
Learning T-SQL
It’s worth your while becoming proficient in SQL. If you’d like to learn a lot about T-SQL in a hurry, our Writing T-SQL Queries for SQL Server course is online, on-demand, and low cost.
2025-04-07