The Update Statement

 < Day Day Up > 



The Update Statement

The Update statement changes the values for one or more columns in the table. Here is its syntax:

Update <table>
Set <column> = <value> [, <column> = <value>]…
[Where <expression>]

Where <table> is the name of the table that you wish to update, <column> is the name of the column in the table, <value> is the new value that will be stored in the column, and <expression> is true for all the rows that should be updated.

The Update statement provides a method that permits you to change the value of one or more columns in the table. You must explicitly specify each column that you wish to change, along with the column’s new value. Also remember that the Update statement can include a Where clause. This Where clause is identical to the one you use in the Select statement and it works just like you would expect. Only the rows that match the expression in the Where clause will be updated—the other rows will remain unchanged.

Tip 

Limit Your Exposure
If your Update statement doesn’t have a Where clause, ask yourself “Do I really want to change all the rows in the table?” If your answer is no, you had better double-check the statement before you try to execute it.

In this example, the Where clause is used to identify all the rows that contain a Null value in the DateUpdated field. The DateUpdated column is then set to ‘01-Jan-2003’.

Update Customers
Set DateUpdated = ’01-Jan-2003’
Where DateUpdated Is Null



 < Day Day Up > 



Microsoft Excel 2003 Programming Inside Out
Microsoft Office Excel 2003 Programming Inside Out (Inside Out (Microsoft))
ISBN: 0735619859
EAN: 2147483647
Year: 2006
Pages: 161

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net