Updating Data
SQLUpdate modifies data in a database. An alternative, using raw SQL, is described in "Updating Data with Raw SQL".
If you find that the examples in this tutorial do not work as shown, you may need to install or restore the example database with the "DatabaseLink`DatabaseExamples`" package, as described in "Using the Example Databases".
The result of SQLUpdate is an integer specifying the number of rows affected by the query.
SQLUpdate[conn,table,{columns},{values},opts] | update data in a database |
SQLUpdate[conn,table,{columns},{values},condition,opts] | update data in a database using a condition |
Here is an example that updates data. This loads DatabaseLink and connects to the demo database.
A new table, TEST, is created and data is inserted.
SQLSelect shows the values in the table.
SQLUpdate updates the elements in the database and SQLSelect shows the result.
Typically, it is useful to set a condition for an update, with the condition specifying which rows should be updated. (For more information on conditions, see "Selecting Data".) In the following example, another row is inserted into the database.
Here an update is given for rows for which the entry in the first column is less than 15.
SQLUpdate accepts one option.
option name | default value | |
"Timeout" | Automatic | set the timeout for a query |
Option of SQLUpdate.
The option "Timeout" can be used to cancel a query if it takes too long to execute.