Modifying with SQL UPDATE

 < Day Day Up > 

Modifying with SQL UPDATE

A SQL UPDATE statement is the same as the update query executed by the Access user interface to modify existing data. This statement uses the following syntax:

 

 UPDATE datasource SET col1 = expression[, col2 = expression, ...] [WHERE condition] 

Given the nature of the statement's purpose, you don't use the GROUP BY, HAVING, or even the ORDER BY clauses with this statement. In addition, UPDATE doesn't return a resultset, but Access displays a message telling you how many records will be updated and asking you to confirm the action. For instance, this simple UPDATE changes all the occurrences of California in the State field in the Clients table to CA:

 

 UPDATE Clients SET State = "CA" WHERE State = "California" 

TIP

Before updating data via an action query, such as UPDATE, create a copy of the data source. That way, if something goes wrong, you have a copy of the unchanged data. After confirming that the changes are correct, you can delete the copy.


Modifying data won't usually violate referential integrity, unless you're changing a primary or foreign key value, which you shouldn't do anyway. However, changes must respect properties and validation rules in place. When running updates via code, include error handling for these potential errors.

     < Day Day Up > 


    Automating Microsoft Access with VBA
    Automating Microsoft Access with VBA
    ISBN: 0789732440
    EAN: 2147483647
    Year: 2003
    Pages: 186

    Similar book on Amazon

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