Inserting Selected Rows from the Database

You can insert any number of rows of data, based on the results of a general SELECT statement.

To insert data from other tables in the current database, or from a database that is defined as a specialty data store to SAP Sybase IQ, use the INSERT statement.

For maximum efficiency, insert as many rows as possible in one INSERT statement. To insert additional sets of rows after the first insert, use additional INSERT statements.

Like other SQL databases, SAP Sybase IQ inserts data by matching the order in which columns are specified in the destination column list and the select list; that is, data from the first column in the select list is inserted into the first destination column, and so on. For both INSERT SELECT and INSERT VALUES, if you omit destination column names, SAP Sybase IQ inserts data into columns in the order in which they were created.

The tables you are inserting into must exist in the database you are currently connected to. SAP Sybase IQ inserts the data into all indexes for the destination columns.

The columns in the table in the select list and in the table must have the same or compatible data types. In other words, the selection’s value must be, or must be able to be converted to, the data type of the table’s column.

With this form of the INSERT statement you can specify any of the insert-load-options.

Example

This example shows an insert from one table, partsupp, to another, lineitem, within the same database.

The data from the source column l_quantity is inserted into the destination column ps_availqty.

INSERT INTO partsupp(ps_availqty)
SELECT l_quantity FROM lineitem
Related concepts
Inserting Specified Values Row by Row