Deleting Data

SQLDelete deletes data from a database. An alternative, using raw SQL, is described in "Deleting 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 SQLDelete is an integer specifying the number of rows affected by the query. Thus, if three rows are removed, the result is three, and if no rows are removed, the result is zero.

SQLDelete[table]delete data from a database
SQLDelete[table,condition]delete data from a database using a condition

Deleting data from a database.

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

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

The following deletes all the data from the table. Two rows were deleted, and the result is two.

SQLSelect verifies that all the data has been removed from the table.

This restores the data in the database.

Here, a condition is used in the SQLDelete command, so that only rows for which the entry in the first column is greater than 15 are deleted. This deletes one row, and hence the result is one.

SQLSelect verifies that one row was removed from the table.

SQLDelete accepts one option.

option name
default value
"Timeout"$SQLTimeoutset the timeout for a query

Option of SQLDelete.

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.