update syntax  Assigning variables in the set clause

Chapter 7: Adding, Changing, and Deleting Data

Using the set clause with update

The set clause specifies the columns and the changed values. The where clause determines which row or rows are to be updated. If you do not have a where clause, the specified columns of all the rows are updated with the values given in the set clause.

NoteBefore trying the examples in this section, make sure you know how to reinstall the pubs2 database. See the installation and configuration guide for your platform for instructions on installing the pubs2 database.

For example, if all the publishing houses in the publishers table move their head offices to Atlanta, Georgia, this is how you update the table:

update publishers 
set city = "Atlanta", state = "GA"

In the same way, you can change the names of all the publishers to NULL with:

update publishers 
set pub_name = null

You can also use computed column values in an update. To double all the prices in the titles table, use:

update titles 
set price = price * 2

Since there is no where clause, the change in prices is applied to every row in the table.





Copyright © 2005. Sybase Inc. All rights reserved. Assigning variables in the set clause

View this book as PDF