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 »

Inserting Data

SQLInsert inserts data into a database. An alternative, using raw SQL, is described in "Inserting 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 SQLInsert is an integer specifying the number of rows affected by the query. For a single insert this will be one, since you can only insert one row at a time. SQLInsert also supports a batch insert, as demonstrated in "Performance: Batch Operation".
SQLInsert[conn,table,{columns},{values},opts]insert data into a database
SQLInsert[conn,table,{columns},{{values}},opts]batch insert data into a database

Inserting data into a database.

Here is an example that inserts data. This loads DatabaseLink and connects to the demo database.
Click for copyable input
A new table, TEST, is created. The details of this command are described in "Creating Tables".
Click for copyable input
SQLInsert inserts data into this table.
Click for copyable input
SQLSelect verifies the data stored in the database.
Click for copyable input
Finally, a batch insert is carried out. The result is a list of the number of lines that are modified.
Click for copyable input
SQLSelect shows that there are now three rows in this table.
Click for copyable input
SQLInsert accepts one option.
option name
default value
"Timeout"Automaticset the timeout for a query

Option of SQLInsert.

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
The details of how Mathematica expressions are mapped to types stored in the database is discussed in "Data Type Mapping".