SQL Server
SQL Server: UPDATE Statement
This SQL Server tutorial explains how to use the UPDATE statement in SQL Server (Transact-SQL) with syntax and examples.
Description
The SQL Server (Transact-SQL) UPDATE statement is used to update existing records in a table in a SQL Server database. There are 3 syntaxes for the UPDATE statement depending on whether you are performing a traditional update or updating one table with data from another table.
Syntax
The syntax for the UPDATE statement when updating one table in SQL Server (Transact-SQL) is:
UPDATE table SET column1 = expression1, column2 = expression2, ... [WHERE conditions];
OR
The syntax for the UPDATE statement when updating one table with data from another table in SQL Server (Transact-SQL) is:
UPDATE table1 SET column1 = (SELECT expression1 FROM table2 WHERE conditions) [WHERE conditions];
OR
The syntax for the SQL Server UPDATE statement when updating one table with data from another table is:
UPDATE table1 SET table1.column = table2.expression1 FROM table1 INNER JOIN table2 ON (table1.column1 = table2.column1) [WHERE conditions];
Parameters or Arguments
- column1, column2
- The columns that you wish to update.
- expression1, expression2
- The new values to assign to the column1, column2. So column1 would be assigned the value of expression1, column2 would be assigned the value of expression2, and so on.
- WHERE conditions
- Optional. The conditions that must be met for the update to execute.
Example - Update single column
Let's look at a very simple SQL Server UPDATE query example.
For example: