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 "DatabaseLink`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 1, 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".
SQLInsert inserts data into this table.
SQLSelect verifies the data stored in the database.
Finally, a batch insert is carried out. The result is a list of the number of lines that are modified.
SQLSelect shows that there are now three rows in this table.
SQLInsert accepts three options.
option name | default value | |
"Timeout" | $SQLTimeout | set the timeout for a query |
"BatchSize" | 1000 | process inserts in batches of this many records |
"JavaBatching" | True | perform parameter batching in Java layer instead of Wolfram Language layer |
Options 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 Wolfram Language expressions are mapped to types stored in the database is discussed in "Data Type Mapping".