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.
A new table,
TEST, is created. The details of this command are described in
"Creating Tables".
| Out[3]= |  |
SQLInsert inserts data into this table.
| Out[4]= |  |
SQLSelect verifies the data stored in the database.
| Out[5]= |  |
Finally, a batch insert is carried out. The result is a list of the number of lines that are modified.
| Out[6]= |  |
SQLSelect shows that there are now three rows in this table.
| Out[7]= |  |
SQLInsert accepts one option.
| | |
| "Timeout" | Automatic | set 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.
The details of how
Mathematica expressions are mapped to types stored in the database is discussed in
"Data Type Mapping".