Updating Data with Raw SQL

The raw SQL command UPDATE updates data in a database. An alternative is to use the Wolfram Language command SQLUpdate, described in "Updating Data".

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

When updating data, the result of SQLExecute is an integer specifying the number of rows affected by the query.

Here is an example that updates data. This loads DatabaseLink and connects to the demo database.

As discussed in "Creating Tables with Raw SQL", the ADDRESSES and MAILER tables should be created.

This executes an SQL statement that updates a row in the MAILER table. This query updates the SENDMAILER column based on the value of USERNAME. Many update statements may be created using conditions that work with values in columns.

A SELECT statement verifies that the data has been changed in the table.

Using prepared statements, you can dynamically create SQL statements that update data within the database. You can combine this with a simple Wolfram Language function. This example updates the address for a particular user.

A SELECT statement verifies that the data has been changed in the table.

The same restrictions that apply to inserts also apply to updates. Thus, if you try to update an ADDRESS value to equal the ADDRESS value of another row, an error will be returned; this table requires them to be unique.

This deletes the tables and closes the connection.