Advanced PowerBuilder

HomePrevious Lesson: The UPDATE Statement
Next Lesson: The DELETE Statement

The INSERT Statement

You can execute two forms of the INSERT statement. The following format inserts a single row into the 'product_master' table.
INSERT INTO guest.product_master 
( product_no, product_description, product_balance,
product_reorder_level,product_measuring_unit )
VALUES ( :li_ProductNo, :lDesc, :lBal, :lROrdLvl, :lMsUnt);

The second format inserts more than one row using a single statement. Suppose you wanted to insert all records from 'product_master' table into a history table product_master. You could use the following code:
INSERT INTO product_master ( <column list> )
SELECT < column list > FROM product_master ;

where you replace <column list> with the list of all the columns in the table. If you have a table with many columns, this can turn into a long SQL statement. However, PowerBuilder does support the asterisk wildcard character (*), which allows you to select all the columns at once:
// Sybase supports selecting values from a table 
// and inserting into the same table.
INSERT INTO product_master 
SELECT * FROM product_master ;

Inserting into the table from which you are selecting may not work with all databases, so you will have to check with your specific database vendor's documentation.
HomePrevious Lesson: The UPDATE Statement
Next Lesson: The DELETE Statement