Tuesday, October 23, 2007

Insert All:

A powerful statement that allows inserting into multiple tables at once by performing a select from the table of all the columns needed, and inserting each column's values into whichever of the target tables that is specified.

The basic syntax is something like

INSERT ALL
INTO table1 VALUES(val_A, val_B)
INTO table2 VALUES(val_C, val_D)
SELECT tmp_a val_A, tmp_b val_B, tmp_c val_C, tmp_d val_D
FROM tmp_table WHERE ...

This will insert multiple rows (any matching the where clause of the select) into both table1 and table2.

No comments: