4.2. UPDATE

The UPDATE command changes existing data in a table.

4.2.1. UPDATE—Basic Syntax

The complete syntax and the arguments of UPDATE can be found on page 448, in section 4.2.2. The following code shows the basics of the UPDATE syntax and some examples of its use.

Syntax
UPDATE { table_name | view_name | rowset_function_limited }
  SET     column_name
							= { expression | DEFAULT | NULL } [ ,...n ]
  [ WHERE < search_condition > ]
4.2.1.1. Examples of UPDATE
Example

Let's first create a sample database with some sample data to play with. (Execute each “SQL:” section separately or add “go” after each to make it a separate batch.)

SQL
													CREATE DATABASE mydb
													USE mydb
													SELECT  *  INTO shippers
													FROM northwind.dbo.shippers
												

Display the data before making ...

Get Transact-SQL Desk Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.