5. Working with a Database : How You Can Access a Database with Standard SQL Statements : How You Can Use the Insert Statement
 
Share this page                  
How You Can Use the Insert Statement
The insert statement adds new rows to a database table. The values that populate the new rows can come from any of the following places:
Variables associated with the current frame:
Simple variables
Attributes of reference variables
Columns in a dynamic array
Global variables
A subselect
Constants
Expression results
Each insert statement adds one row to the database. For example, the following statement adds a single new customer record to the customer database table:
insert into customer (acctno, cphone, cname,
    addr, ccity, cstate, czip, cdistrict, cstatus,
    cacctbal)
values (:acctno, :cphone, :cname, :caddr,
    :ccity, :cstate, :czip, :cdistrict,
    :cstatus,:cacctbal);
You may insert several rows into a table using a loop. For example:
i = 1
for i = 1 to new_customers.lastrow do
    insert into customer
            (acctno, cphone, cname)
    values
            (
                :new_customers[i].acctno,
                :new_customers[i].cphone,
                :new_customers[i].cname
            )
endfor;
For a discussion of processing arrays using the row state attribute, see Working with Arrays, Table Fields, and Collections (see Working with Arrays, Table Fields, and Collections).