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
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 |
Updating data in a database.
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.
| Out[5]= |  |
SQLUpdate updates the elements in the database and
SQLSelect shows the result.
| Out[7]= |  |
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.
| Out[9]= |  |
Here an update is given for rows for which the entry in the first column is less than 15.
| Out[11]= |  |
SQLUpdate accepts one option.
| | |
| "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.
This drops the table and closes the connection.