DATABASELINK TUTORIAL

Updating Data
This feature is not supported on the Wolfram Cloud.

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 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.

In[1]:=
Click for copyable input

A new table, TEST, is created and data is inserted.

In[2]:=
Click for copyable input

SQLSelect shows the values in the table.

In[4]:=
Click for copyable input
Out[4]=

SQLUpdate updates the elements in the database and SQLSelect shows the result.

In[5]:=
Click for copyable input
Out[6]=

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.

In[7]:=
Click for copyable input
Out[8]=

Here an update is given for rows for which the entry in the first column is less than 15.

In[9]:=
Click for copyable input
Out[10]=

SQLUpdate accepts one option.

option name
default value
"Timeout"Automaticset the timeout for a query

Option of SQLUpdate.

The option can be used to cancel a query if it takes too long to execute.

This drops the table and closes the connection.

In[11]:=
Click for copyable input