This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
DatabaseLink TutorialFunctions »

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 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.
Click for copyable input
A new table, TEST, is created and data is inserted.
Click for copyable input
The following deletes all the data from the table. Two rows were deleted, and the result is two.
Click for copyable input
SQLSelect verifies that all the data has been removed from the table.
Click for copyable input
This restores the data in the database.
Click for copyable input
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.
Click for copyable input
SQLSelect verifies that one row was removed from the table.
Click for copyable input
SQLDelete accepts one option.
option name
default value
"Timeout"Automaticset 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.
Click for copyable input