Sybase 12.4.2 Server User Manual


 
Inserting selected rows from the database
192
SKIP
number-of-rows
START ROW ID
number
This form of the INSERT statement lets you insert any number of rows of data,
based on the results of a general
SELECT 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, Adaptive Server 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, Adaptive Server 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. Adaptive Server 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. See “Converting
data on insertion” for more information about data types and conversion
options.
With this form of the
INSERT statement you can specify any of the following
insert-load-options:
The
START ROW ID option lets you perform a partial-width insert. Read
“Partial-width insertions” before you specify this option.
For an explanation of all of these options, see “Specifying 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
Inserting from a different database
You can insert data from tables in any accessible database: