Changing Data by Using UPDATE

The UPDATE statement can change data values in single rows, groups of rows, or all the rows in a table or view. It can also be used to update rows in a remote server by using either a linked server name or the OPENROWSET, OPENDATASOURCE, and OPENQUERY functions, as long as the OLE DB provider used to access the remote server supports updates. An UPDATE statement referencing a table or view can change the data in only one base table at a time.

The UPDATE statement has the following major clauses:

  • SET
    Contains a comma-separated list of the columns to be updated and the new value for each column, in the form column_name = expression. The value supplied by the expressions includes items such as constants, values selected from a column in another table or view, or values calculated by a complex expression. For more information, see Changing Data by Using the SET Clause.
  • FROM
    Identifies the tables or views that supply the values for the expressions in the SET clause, and optional join conditions between the source tables or views. For more information, see Changing Data by Using the FROM Clause.
  • WHERE
    Specifies the search condition that defines the rows from the source tables and views that qualify to provide values to the expressions in the SET clause. For more information, see Changing Data by Using the WHERE Clause.

The following example uses the UPDATE statement to increase the price of all the AdventureWorks products associated with product model 37 by 10 percent:

USE AdventureWorks;
GO
UPDATE AdventureWorks.Production.Product
SET ListPrice = ListPrice * 1.1
WHERE ProductModelID = 37;
GO

To change data using UPDATE

UPDATE (Transact-SQL)

See Also

Other Resources

Inserting Data into a Table
Deleting Data in a Table

Help and Information

Getting SQL Server 2005 Assistance