Applications that perform many INSERT statements in succession may be improved by using INSERT n ROWS. With this clause, you can insert one or more rows of data from a host structure array into a target table. This array must be an array of structures where the elements of the structure correspond to columns in the target table.
An SQL application that loops over an INSERT...VALUES statement (without the n ROWS clause) can be improved by using the INSERT n ROWS statement to insert multiple rows into the table. After the application has looped to fill the host array with rows, a single INSERT n ROWS statement can be run to insert the entire array into the table. The statement runs faster because the SQL run-time was only called once and all the data was simultaneously inserted into the target table.
In the following table, the program attempted to INSERT 100 rows into a table. Note the differences in the number of calls to SQL run-time and to the database manager when blocking can be performed.
Database Manager Not Using Blocking | Database Manager Using Blocking | |
---|---|---|
Single-Row INSERT Statement | 100 SQL run-time calls 100 database calls | 100 SQL run-time calls 1 database call |
Multiple-Row INSERT Statement | 1 SQL run-time call 100 database calls | 1 SQL run-time call 1 database call |