Database Toolbox User's Guide
  Go to function:
    Search    Help Desk 
update    Examples   See Also

Replace data in database table with data from MATLAB cell array

Syntax

Description

update(conn, 'tablename', colnames, data, 'whereclause') exports data from the MATLAB cell array, data, into the database table, tablename, via the database connection conn. It replaces existing records in the table as specified by the SQL command, whereclause. Specify the column names for tablename in the MATLAB cell array, colnames.

The status of the autocommit flag determines if update automatically commits the data or if an SQL commit command is needed. View the autocommit flag status for the connection using get and change it using set. Perform an SQL commit or rollback using exec.

To add new rows instead of replacing existing data, use insert.

Examples

Example 1 - Update a record

In the Birthdays table, update the record where First_Name is Jean, replacing the current value for Age with the new value, 40. The connection is conn.

Define a cell array containing the column name you are updating, Age:

Define a cell array containing the new data:

Perform the update:

Example 2 - Update followed by SQL rollback

This example shows a database update when the autocommit flag is off and the data is then rolled back. First set the autocommit flag to off for database connection connect:

Update the data in the column names specified by C of the Error_Rate table for the record selected by whereClause using data contained in the cell array data:

The data was written but not committed.

Roll back the data:

The update was reversed; the data in the table is the same as it was before update was run.

See Also

database, insert, set

[ Previous | Help Desk | Next ]